Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RestfulapiController.php 25KB

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