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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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. $cpn_date = ''; $cpn_time = '';
  77. if (!empty($c->cpn_created))
  78. {
  79. $cpn_date = Carbon::parse($c->cpn_created)->format("D, d M, 'y");
  80. $cpn_time = Carbon::parse($c->cpn_created)->format("g:i A");
  81. }
  82. if($c->jenis == 'Pelbagai_KT'){
  83. array_push($data,array(
  84. "_id" => $c->_id,
  85. "jenis" => $c->jenis,
  86. "kpd"=> $c->kpd,
  87. "nama"=> $c->nama,
  88. "identity" => $c->identity,
  89. "no_tel" => $c->no_tel,
  90. "nama_syarikat" => $c->nama_syarikat,
  91. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat),
  92. "no_akaun_lesen" => $c->no_akaun_lesen,
  93. "alamat" => $c->alamat,
  94. "no_plate" => strtoupper($c->no_plate),
  95. "no_cukai_jalan" => $c->no_cukai_jalan,
  96. "latlong" => $c->latlong,
  97. "nama_kawasan" => $c->nama_kawasan,
  98. "nama_taman" => $c->nama_taman,
  99. "nama_jalan" => $c->nama_jalan,
  100. "jbkod" => $c->Department->jnama,
  101. "akta" => $c->DeedLaw->nama,
  102. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  103. "catatan" => $c->catatan,
  104. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  105. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  106. "amount_payment" => $c->amount_payment,
  107. "receipt" => $c->receipt,
  108. "dikeluarkan" => $c->dikeluarkan,
  109. "status" => $c->status,
  110. "updated_at" => $c->updated_at->toDateTimeString(),
  111. "created_at" => $c->created_at->toDateTimeString(),
  112. "notice_created" => $c->notice_created,
  113. "cpn_created_date" => $cpn_date,
  114. "cpn_created_time" => $cpn_time,
  115. ));
  116. }else if($c->jenis == 'Pelbagai_JPB'){
  117. array_push($data,array(
  118. "_id" => $c->_id,
  119. "jenis" => $c->jenis,
  120. "kpd"=> $c->kpd,
  121. "nama"=> $c->nama,
  122. "identity" => $c->identity,
  123. "no_tel" => $c->no_tel,
  124. "nama_syarikat" => $c->nama_syarikat,
  125. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat),
  126. "no_akaun_lesen" => $c->no_akaun_lesen,
  127. "alamat" => $c->alamat,
  128. "no_plate" => strtoupper($c->no_plate),
  129. "no_cukai_jalan" => $c->no_cukai_jalan,
  130. "latlong" => $c->latlong,
  131. "nama_kawasan" => $c->nama_kawasan,
  132. "nama_taman" => $c->nama_taman,
  133. "nama_jalan" => $c->nama_jalan,
  134. "jbkod" => $c->Department->jnama,
  135. "akta" => $c->DeedLaw->nama,
  136. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  137. "catatan" => $c->catatan,
  138. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  139. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  140. "amount_payment" => $c->amount_payment,
  141. "receipt" => $c->receipt,
  142. "dikeluarkan" => $c->dikeluarkan,
  143. "status" => $c->status,
  144. "updated_at" => $c->updated_at->toDateTimeString(),
  145. "created_at" => $c->created_at->toDateTimeString(),
  146. "notice_created" => $c->notice_created,
  147. "cpn_created_date" => $cpn_date,
  148. "cpn_created_time" => $cpn_time,
  149. ));
  150. }else if($c->jenis == 'Pelbagai_LESEN'){
  151. array_push($data,array(
  152. "_id" => $c->_id,
  153. "jenis" => $c->jenis,
  154. "kpd"=> $c->kpd,
  155. "nama"=> $c->nama,
  156. "identity" => $c->identity,
  157. "no_tel" => $c->no_tel,
  158. "nama_syarikat" => $c->nama_syarikat,
  159. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat),
  160. "no_akaun_lesen" => $c->no_akaun_lesen,
  161. "alamat" => $c->alamat,
  162. "no_plate" => strtoupper($c->no_plate),
  163. "no_cukai_jalan" => $c->no_cukai_jalan,
  164. "latlong" => $c->latlong,
  165. "nama_kawasan" => $c->nama_kawasan,
  166. "nama_taman" => $c->nama_taman,
  167. "nama_jalan" => $c->nama_jalan,
  168. "jbkod" => $c->Department->jnama,
  169. "akta" => $c->DeedLaw->nama,
  170. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  171. "catatan" => $c->catatan,
  172. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  173. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  174. "amount_payment" => $c->amount_payment,
  175. "receipt" => $c->receipt,
  176. "dikeluarkan" => $c->dikeluarkan,
  177. "status" => $c->status,
  178. "updated_at" => $c->updated_at->toDateTimeString(),
  179. "created_at" => $c->created_at->toDateTimeString(),
  180. "notice_created" => $c->notice_created,
  181. "cpn_created_date" => $cpn_date,
  182. "cpn_created_time" => $cpn_time,
  183. ));
  184. }else if($c->jenis == 'Pelbagai_PA'){
  185. array_push($data,array(
  186. "_id" => $c->_id,
  187. "jenis" => $c->jenis,
  188. "kpd"=> $c->kpd,
  189. "nama"=> $c->nama,
  190. "identity" => $c->identity,
  191. "no_tel" => $c->no_tel,
  192. "nama_syarikat" => $c->nama_syarikat,
  193. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat),
  194. "no_akaun_lesen" => $c->no_akaun_lesen,
  195. "alamat" => $c->alamat,
  196. "no_plate" => strtoupper($c->no_plate),
  197. "no_cukai_jalan" => $c->no_cukai_jalan,
  198. "latlong" => $c->latlong,
  199. "nama_kawasan" => $c->nama_kawasan,
  200. "nama_taman" => $c->nama_taman,
  201. "nama_jalan" => $c->nama_jalan,
  202. "jbkod" => $c->Department->jnama,
  203. "akta" => $c->DeedLaw->nama,
  204. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  205. "catatan" => $c->catatan,
  206. "bil_haiwan" => $c->bil_haiwan,
  207. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  208. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  209. "amount_payment" => $c->amount_payment,
  210. "receipt" => $c->receipt,
  211. "dikeluarkan" => $c->dikeluarkan,
  212. "status" => $c->status,
  213. "updated_at" => $c->updated_at->toDateTimeString(),
  214. "created_at" => $c->created_at->toDateTimeString(),
  215. "notice_created" => $c->notice_created,
  216. "cpn_created_date" => $cpn_date,
  217. "cpn_created_time" => $cpn_time,
  218. ));
  219. }else if($c->jenis == 'Parkir'){
  220. array_push($data,array(
  221. "_id" => $c->_id,
  222. "nama" => $c->nama,
  223. "identity" => $c->identity,
  224. "jenis" => $c->jenis,
  225. "kpd"=> $c->kpd,
  226. "no_plate" => strtoupper($c->no_plate),
  227. "no_cukai_jalan" => $c->no_cukai_jalan,
  228. "jenis_kenderaan" => $c->jenis_kenderaan,
  229. "model_kenderaan" => $c->model_kenderaan,
  230. "warna_kenderaan" => $c->warna_kenderaan,
  231. "nama_taman" => $c->nama_taman,
  232. "nama_jalan" => $c->nama_jalan,
  233. "no_parking" => $c->no_parking,
  234. "latlong" => $c->latlong,
  235. "jbkod" => $c->Department->jnama,
  236. "akta" => $c->DeedLaw->nama,
  237. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  238. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  239. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  240. "amount_payment" => $c->amount_payment,
  241. "receipt" => $c->receipt,
  242. "dikeluarkan" => $c->dikeluarkan,
  243. "status" => $c->status,
  244. "updated_at" => $c->updated_at->toDateTimeString(),
  245. "created_at" => $c->created_at->toDateTimeString(),
  246. "notice_created" => $c->notice_created,
  247. "cpn_created_date" => $cpn_date,
  248. "cpn_created_time" => $cpn_time,
  249. ));
  250. }
  251. }
  252. return $this->sendResponse($data, 'Result Found');
  253. }else {
  254. return $this->sendResponse('', 'No Result');
  255. }
  256. }else{
  257. return $this->sendError('Search field is compulsory!', '');
  258. }
  259. }else{
  260. return $this->sendError('Invalid Api Key', '');
  261. }
  262. }else{
  263. return $this->sendError('Invalid Api Key', '');
  264. }
  265. }
  266. /**
  267. * Create update compound controller.
  268. *
  269. * @return json
  270. */
  271. public function updatePaymentIntegrasi(Request $request){
  272. $api_integrasi = ApiIntegration::where('key', $request->key)->first();
  273. if(!empty($api_integrasi)){
  274. if($api_integrasi->status == 'active'){
  275. $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kp)->first();
  276. if(!empty($compound)){
  277. if($compound->status != 'Berbayar'){
  278. $compound->status = 'Berbayar';
  279. $compound->receipt = $request->receipt;
  280. $compound->amount_payment = $request->amount;
  281. $compound->save();
  282. $now = Carbon::now();
  283. $gDate = $now->format('F Y');
  284. $historyData = [
  285. 'tarikh_kumpulan' => $gDate,
  286. ];
  287. $subHistory = [
  288. 'no_siri' => $compound->ConfidentialFile->no_siri,
  289. 'tajuk' => "Pembayaran kompaun ".$request->orderid." telah dibuat secara 'online'",
  290. 'huraian' => "Pembayaran kompaun ".$request->orderid." telah dijelaskan pada hari ini.",
  291. ];
  292. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  293. if(!empty($groupByDate)){
  294. $groupByDate->subhistory()->create($subHistory);
  295. $compound->ConfidentialFile->history()->attach($groupByDate);
  296. }else{
  297. $history = History::create($historyData);
  298. $history->subhistory()->create($subHistory);
  299. $compound->ConfidentialFile->history()->attach($history);
  300. }
  301. $kpd = Compound::where('kpd', $request->kp)->first();
  302. $department = Department::where('_id',$kpd->jbkod)->first();
  303. $faulty = Faulty::where('_id',$kpd->seksyen_kesalahan)->first();
  304. $akta = DeedLaw::where('_id',$faulty->deed_law_id)->first();
  305. $data = [
  306. "_id" => $kpd->_id,
  307. "kpd"=> $kpd->kpd,
  308. "nama"=> $kpd->nama,
  309. "identity" => $kpd->identity,
  310. "nama_syarikat" => $kpd->nama_syarikat,
  311. "no_daftar_syarikat" => $kpd->no_daftar_syarikat,
  312. "alamat" => $kpd->alamat,
  313. "no_plate" => $kpd->no_plate,
  314. "latlong" => $kpd->latlong,
  315. "jbkod" => $department->jnama,
  316. "akta" => "[".$akta->akkod."] ".$akta->nama,
  317. "seksyen_kesalahan" => "[".$faulty->sketr."] ".$faulty->nama,
  318. "jumlah_asal_kompaun" => $kpd->jumlah_asal_kompaun,
  319. "jumlah_kemaskini_kompaun" => $kpd->jumlah_kemaskini_kompaun,
  320. "amount_payment" => $kpd->amount_payment,
  321. "receipt" => $kpd->receipt,
  322. "dikeluarkan" => $kpd->dikeluarkan,
  323. "status" => $kpd->status,
  324. "updated_at" => $kpd->updated_at->toDateTimeString(),
  325. "created_at" => $kpd->created_at->toDateTimeString(),
  326. ];
  327. return $this->sendResponse($data, 'Successfully update compound status');
  328. }else{
  329. return $this->sendResponse('', 'This compound already been paid');
  330. }
  331. }else{
  332. return $this->sendError('Record compound not found!', '');
  333. }
  334. }else{
  335. return $this->sendError('Invalid Api Key', '');
  336. }
  337. }else{
  338. return $this->sendError('Invalid Api Key', '');
  339. }
  340. }
  341. public function compoundToEPBT()
  342. {
  343. $compound = Compound::with('Department','DeedLaw','Faulty','StaffDetail')->where('jenis', 'Pelbagai_JPB')->get();
  344. dd($compound);
  345. if(!empty($compound))
  346. {
  347. $data = [];
  348. foreach ($compound as $key => $c)
  349. {
  350. if($c->jenis == 'Pelbagai_KT')
  351. {
  352. $data = [
  353. 'no_kom' => $c->kpd,
  354. 'jenis' => $c->jenis,
  355. 'nama' => $c->nama,
  356. 'no_ic' => $c->identity,
  357. 'no_tel' => $c->no_telefon,
  358. 'nama_syarikat' => $c->nama_syarikat,
  359. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  360. 'no_akaun_lesen' => $c->no_akaun_lesen,
  361. 'alamat' => $c->alamat,
  362. 'jabatan' => $c->Department->jnama,
  363. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  364. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  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_JPB')
  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 == 'Pelbagai_PA')
  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. 'bil_haiwan' => $c->bil_haiwan,
  410. 'catatan' => $c->catatan,
  411. 'latlong' => $c->latlong,
  412. 'status' =>$c->status,
  413. 'amaun_bayar' => $c->amount_payment,
  414. 'receipt' => $c->receipt,
  415. ];
  416. }
  417. if($c->jenis == 'Pelbagai_LESEN')
  418. {
  419. $data = [
  420. 'no_kom' => $c->kpd,
  421. 'jenis' => $c->jenis,
  422. 'nama' => $c->nama,
  423. 'no_ic' => $c->identity,
  424. 'no_tel' => $c->no_telefon,
  425. 'nama_syarikat' => $c->nama_syarikat,
  426. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  427. 'no_akaun_lesen' => $c->no_akaun_lesen,
  428. 'alamat' => $c->alamat,
  429. 'jabatan' => $c->Department->jnama,
  430. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  431. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  432. 'catatan' => $c->catatan,
  433. 'latlong' => $c->latlong,
  434. 'status' =>$c->status,
  435. 'amaun_bayar' => $c->amount_payment,
  436. 'receipt' => $c->receipt,
  437. ];
  438. }
  439. if($c->jenis == 'Parkir')
  440. {
  441. $data = [
  442. 'no_kom' => $c->kpd,
  443. 'jenis' => $c->jenis,
  444. 'nama' => $c->nama,
  445. 'no_ic' => $c->identity,
  446. 'no_tel' => $c->no_telefon,
  447. 'nama_syarikat' => $c->nama_syarikat,
  448. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  449. 'no_akaun_lesen' => $c->no_akaun_lesen,
  450. 'alamat' => $c->alamat,
  451. 'jabatan' => $c->Department->jnama,
  452. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  453. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  454. 'catatan' => $c->catatan,
  455. 'latlong' => $c->latlong,
  456. 'status' =>$c->status,
  457. 'amaun_bayar' => $c->amount_payment,
  458. 'receipt' => $c->receipt,
  459. ];
  460. }
  461. }
  462. return $this->sendResponse($data, 'Successfully update compound status');
  463. }
  464. }
  465. }