Dashboard sipadu mbip
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

RestfulapiController.php 25KB

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