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

RestfulapiController.php 19KB

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