Dashboard sipadu mbip
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

RestfulapiController.php 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. //validate api key
  60. $api_integrasi = ApiIntegration::where('key', $request->key)->first();
  61. if(!empty($api_integrasi)){
  62. if($api_integrasi->status == 'active'){
  63. if($request->filled('mobile')){
  64. $jenis = $request->jenis ;
  65. $ic = $request->ic_num;
  66. $notice = $request->non;
  67. $kawasan = $request->kawasan;
  68. $taman = $request->taman;
  69. $jalan = $request->jalan;
  70. //get date and convert to ISO format
  71. $date = $request->date;
  72. $compound = Compound::with('Faulty', 'Department', 'DeedLaw')->where('jenis', $jenis)->orWhere('jenis_n', $jenis)
  73. ->orWhere(function($q) use
  74. ($notice, $ic, $date, $jalan, $taman, $kawasan) {
  75. if(!empty($notice) && $notice != '-'){
  76. $q = $q->where('non', 'like', $notice)->orWhere('kpd', 'like', $notice);
  77. }
  78. if(!empty($ic) && $ic != '-'){
  79. $q = $q->where('identity', 'like', $ic);
  80. }
  81. if(!empty($date) && $date != '-'){
  82. $start = Carbon::createFromFormat('Y-m-d', $date)->startOfDay();
  83. $end = Carbon::createFromFormat('Y-m-d', $date)->endOfDay();
  84. $q = $q->whereBetween('created_at', [$start, $end]);
  85. }
  86. if( !empty($kawasan) || !empty($taman) || !empty($jalan) )
  87. {
  88. $q = $q->where('nama_kawasan', $kawasan)->orWhere('nama_taman', $taman)->orWhere('nama_jalan', $jalan);
  89. }
  90. })->get();
  91. }
  92. else if($request->filled('search')){
  93. $search = $request->search;
  94. $compound = Compound::with('Faulty','Department','DeedLaw')->where('kpd','like',$search)->orWhere('non', 'like', $search)
  95. ->orWhere('no_daftar_syarikat', $search)->orWhere('no_plate', $search)->orWhere('identity', $search)->get();
  96. }
  97. else{
  98. return $this->sendError('Could not search!', '');
  99. }
  100. if(count($compound) > 0){
  101. $data = array();
  102. $all_data = array();
  103. foreach($compound as $c){
  104. //check compound & notice created and convert to date & time
  105. $tarikh_n = '-'; $masa_n = '-'; $tarikh = '-'; $masa = '-';
  106. if (!empty($c->created_n))
  107. {
  108. $tarikh_n = Carbon::parse('2020-09-11')->translatedFormat("l, d M, 'y");
  109. $masa_n = Carbon::parse($c->created_c)->format("g:i A");
  110. }
  111. if(!empty($c->created_c))
  112. {
  113. $tarikh = Carbon::parse('2020-09-11')->translatedFormat("l, d M, 'y");
  114. $masa = Carbon::parse($c->created_c)->format("g:i A");
  115. }
  116. //set default data to '-' if not present
  117. array_push($data,array(
  118. "_id" => $c->_id ,
  119. "non" => $c->non ?? '-',
  120. "jenis_notis" => $c->jenis_n ?? '-',
  121. "kpd"=> $c->kpd ?? '-',
  122. "jenis_kompaun" => $c->jenis ?? '-',
  123. "nama"=> $c->nama ?? '-',
  124. "identity" => $c->identity ?? '-',
  125. "no_tel" => $c->no_tel ?? '-',
  126. "nama_syarikat" => $c->nama_syarikat ?? '-',
  127. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat) ?? '-',
  128. "no_akaun_lesen" => $c->no_akaun_lesen ?? '-',
  129. "alamat" => $c->alamat ?? '-',
  130. "no_plate" => strtoupper($c->no_plate) ?? '-',
  131. "no_cukai_jalan" => $c->no_cukai_jalan ?? '-',
  132. "latlong" => $c->latlong ?? '-',
  133. "nama_kawasan" => $c->nama_kawasan ?? '-',
  134. "nama_taman" => $c->nama_taman ?? '-',
  135. "nama_jalan" => $c->nama_jalan ?? '-',
  136. "jbkod" => $c->Department->jnama ?? '-',
  137. "akta_notis" => $c->deedlawNotis->nama ?? '-',
  138. "seksyen_kesalahan_notis" => $c->FaultyNotis->nama ?? '-',
  139. "akta" => $c->DeedLaw->nama ?? '-',
  140. "seksyen_kesalahan" => $c->Faulty->nama ?? '-',
  141. "catatan" => $c->catatan ?? '-',
  142. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun ?? '-',
  143. "amount_payment" => $c->amount_payment ?? '-',
  144. "receipt" => $c->receipt ?? '-',
  145. "notis_dikeluarkan" => $c->dikeluarkan_n ?? '-',
  146. "kompaun_dikeluarkan" => $c->dikeluarkan_n ?? '-',
  147. "status" => $c->status,
  148. "tarikh_notis" => $tarikh_n ,
  149. "masa_notis" => $masa_n ,
  150. "tarikh_kompaun" => $tarikh,
  151. "masa_kompaun" => $masa
  152. ));
  153. array_push($all_data, $data);
  154. }
  155. return $this->sendResponse($data, 'Result Found');
  156. }else {
  157. return $this->sendResponse('', 'No Result');
  158. }
  159. }else{
  160. return $this->sendError('Invalid Api Key', '');
  161. }
  162. }else{
  163. return $this->sendError('Invalid Api Key', '');
  164. }
  165. }
  166. /**
  167. * Create update compound controller.
  168. *
  169. * @return json
  170. */
  171. public function updatePaymentIntegrasi(Request $request){
  172. $api_integrasi = ApiIntegration::where('key', $request->key)->first();
  173. if(!empty($api_integrasi)){
  174. if($api_integrasi->status == 'active'){
  175. $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kp)->first();
  176. if(!empty($compound)){
  177. if($compound->status != 'Berbayar'){
  178. $compound->status = 'Berbayar';
  179. $compound->receipt = $request->receipt;
  180. $compound->amount_payment = $request->amount;
  181. $compound->save();
  182. $now = Carbon::now();
  183. $gDate = $now->format('F Y');
  184. $historyData = [
  185. 'tarikh_kumpulan' => $gDate,
  186. ];
  187. $subHistory = [
  188. 'no_siri' => $compound->ConfidentialFile->no_siri,
  189. 'tajuk' => "Pembayaran kompaun ".$request->orderid." telah dibuat secara 'online'",
  190. 'huraian' => "Pembayaran kompaun ".$request->orderid." telah dijelaskan pada hari ini.",
  191. ];
  192. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  193. if(!empty($groupByDate)){
  194. $groupByDate->subhistory()->create($subHistory);
  195. $compound->ConfidentialFile->history()->attach($groupByDate);
  196. }else{
  197. $history = History::create($historyData);
  198. $history->subhistory()->create($subHistory);
  199. $compound->ConfidentialFile->history()->attach($history);
  200. }
  201. $kpd = Compound::where('kpd', $request->kp)->first();
  202. $department = Department::where('_id',$kpd->jbkod)->first();
  203. $faulty = Faulty::where('_id',$kpd->seksyen_kesalahan)->first();
  204. $akta = DeedLaw::where('_id',$faulty->deed_law_id)->first();
  205. $data = [
  206. "_id" => $kpd->_id,
  207. "kpd"=> $kpd->kpd,
  208. "nama"=> $kpd->nama,
  209. "identity" => $kpd->identity,
  210. "nama_syarikat" => $kpd->nama_syarikat,
  211. "no_daftar_syarikat" => $kpd->no_daftar_syarikat,
  212. "alamat" => $kpd->alamat,
  213. "no_plate" => $kpd->no_plate,
  214. "latlong" => $kpd->latlong,
  215. "jbkod" => $department->jnama,
  216. "akta" => "[".$akta->akkod."] ".$akta->nama,
  217. "seksyen_kesalahan" => "[".$faulty->sketr."] ".$faulty->nama,
  218. "jumlah_asal_kompaun" => $kpd->jumlah_asal_kompaun,
  219. "jumlah_kemaskini_kompaun" => $kpd->jumlah_kemaskini_kompaun,
  220. "amount_payment" => $kpd->amount_payment,
  221. "receipt" => $kpd->receipt,
  222. "dikeluarkan" => $kpd->dikeluarkan,
  223. "status" => $kpd->status,
  224. "updated_at" => $kpd->updated_at->toDateTimeString(),
  225. "created_at" => $kpd->created_at->toDateTimeString(),
  226. ];
  227. return $this->sendResponse($data, 'Successfully update compound status');
  228. }else{
  229. return $this->sendResponse('', 'This compound already been paid');
  230. }
  231. }else{
  232. return $this->sendError('Record compound not found!', '');
  233. }
  234. }else{
  235. return $this->sendError('Invalid Api Key', '');
  236. }
  237. }else{
  238. return $this->sendError('Invalid Api Key', '');
  239. }
  240. }
  241. public function compoundToEPBT()
  242. {
  243. $compound = Compound::with('Department','DeedLaw','Faulty','StaffDetail')->where('jenis', 'Pelbagai_JPB')->get();
  244. if(!empty($compound))
  245. {
  246. $data = [];
  247. foreach ($compound as $key => $c)
  248. {
  249. if($c->jenis == 'Pelbagai_KT')
  250. {
  251. $data = [
  252. 'no_kom' => $c->kpd,
  253. 'jenis' => $c->jenis,
  254. 'nama' => $c->nama,
  255. 'no_ic' => $c->identity,
  256. 'no_tel' => $c->no_telefon,
  257. 'nama_syarikat' => $c->nama_syarikat,
  258. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  259. 'no_akaun_lesen' => $c->no_akaun_lesen,
  260. 'alamat' => $c->alamat,
  261. 'jabatan' => $c->Department->jnama,
  262. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  263. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  264. 'catatan' => $c->catatan,
  265. 'latlong' => $c->latlong,
  266. 'status' =>$c->status,
  267. 'amaun_bayar' => $c->amount_payment,
  268. 'receipt' => $c->receipt,
  269. ];
  270. }
  271. if($c->jenis == 'Pelbagai_JPB')
  272. {
  273. $data = [
  274. 'no_kom' => $c->kpd,
  275. 'jenis' => $c->jenis,
  276. 'nama' => $c->nama,
  277. 'no_ic' => $c->identity,
  278. 'no_tel' => $c->no_telefon,
  279. 'nama_syarikat' => $c->nama_syarikat,
  280. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  281. 'no_akaun_lesen' => $c->no_akaun_lesen,
  282. 'alamat' => $c->alamat,
  283. 'jabatan' => $c->Department->jnama,
  284. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  285. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  286. 'catatan' => $c->catatan,
  287. 'latlong' => $c->latlong,
  288. 'status' =>$c->status,
  289. 'amaun_bayar' => $c->amount_payment,
  290. 'receipt' => $c->receipt,
  291. ];
  292. }
  293. if($c->jenis == 'Pelbagai_PA')
  294. {
  295. $data = [
  296. 'no_kom' => $c->kpd,
  297. 'jenis' => $c->jenis,
  298. 'nama' => $c->nama,
  299. 'no_ic' => $c->identity,
  300. 'no_tel' => $c->no_telefon,
  301. 'nama_syarikat' => $c->nama_syarikat,
  302. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  303. 'no_akaun_lesen' => $c->no_akaun_lesen,
  304. 'alamat' => $c->alamat,
  305. 'jabatan' => $c->Department->jnama,
  306. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  307. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  308. 'bil_haiwan' => $c->bil_haiwan,
  309. 'catatan' => $c->catatan,
  310. 'latlong' => $c->latlong,
  311. 'status' =>$c->status,
  312. 'amaun_bayar' => $c->amount_payment,
  313. 'receipt' => $c->receipt,
  314. ];
  315. }
  316. if($c->jenis == 'Pelbagai_LESEN')
  317. {
  318. $data = [
  319. 'no_kom' => $c->kpd,
  320. 'jenis' => $c->jenis,
  321. 'nama' => $c->nama,
  322. 'no_ic' => $c->identity,
  323. 'no_tel' => $c->no_telefon,
  324. 'nama_syarikat' => $c->nama_syarikat,
  325. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  326. 'no_akaun_lesen' => $c->no_akaun_lesen,
  327. 'alamat' => $c->alamat,
  328. 'jabatan' => $c->Department->jnama,
  329. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  330. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  331. 'catatan' => $c->catatan,
  332. 'latlong' => $c->latlong,
  333. 'status' =>$c->status,
  334. 'amaun_bayar' => $c->amount_payment,
  335. 'receipt' => $c->receipt,
  336. ];
  337. }
  338. if($c->jenis == 'Parkir')
  339. {
  340. $data = [
  341. 'no_kom' => $c->kpd,
  342. 'jenis' => $c->jenis,
  343. 'nama' => $c->nama,
  344. 'no_ic' => $c->identity,
  345. 'no_tel' => $c->no_telefon,
  346. 'nama_syarikat' => $c->nama_syarikat,
  347. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  348. 'no_akaun_lesen' => $c->no_akaun_lesen,
  349. 'alamat' => $c->alamat,
  350. 'jabatan' => $c->Department->jnama,
  351. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  352. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  353. 'catatan' => $c->catatan,
  354. 'latlong' => $c->latlong,
  355. 'status' =>$c->status,
  356. 'amaun_bayar' => $c->amount_payment,
  357. 'receipt' => $c->receipt,
  358. ];
  359. }
  360. }
  361. return $this->sendResponse($data, 'Successfully update compound status');
  362. }
  363. }
  364. }