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

RestfulapiController.php 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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. ));
  172. array_push($all_data, $data);
  173. }
  174. return $this->sendResponse($data, 'Result Found');
  175. }else {
  176. return $this->sendResponse('', 'No Result');
  177. }
  178. }else{
  179. return $this->sendError('Invalid Api Key', '');
  180. }
  181. }else{
  182. return $this->sendError('Invalid Api Key', '');
  183. }
  184. }
  185. /**
  186. * Create update compound controller.
  187. *
  188. * @return json
  189. */
  190. public function updatePaymentIntegrasi(Request $request){
  191. $api_integrasi = ApiIntegration::where('key', $request->key)->first();
  192. if(!empty($api_integrasi)){
  193. if($api_integrasi->status == 'active'){
  194. $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kp)->first();
  195. if(!empty($compound)){
  196. if($compound->status != 'Berbayar'){
  197. $compound->status = 'Berbayar';
  198. $compound->receipt = $request->receipt;
  199. $compound->amount_payment = $request->amount;
  200. $compound->save();
  201. $now = Carbon::now();
  202. $gDate = $now->format('F Y');
  203. $historyData = [
  204. 'tarikh_kumpulan' => $gDate,
  205. ];
  206. $subHistory = [
  207. 'no_siri' => $compound->ConfidentialFile->no_siri,
  208. 'tajuk' => "Pembayaran kompaun ".$request->orderid." telah dibuat secara 'online'",
  209. 'huraian' => "Pembayaran kompaun ".$request->orderid." telah dijelaskan pada hari ini.",
  210. ];
  211. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  212. if(!empty($groupByDate)){
  213. $groupByDate->subhistory()->create($subHistory);
  214. $compound->ConfidentialFile->history()->attach($groupByDate);
  215. }else{
  216. $history = History::create($historyData);
  217. $history->subhistory()->create($subHistory);
  218. $compound->ConfidentialFile->history()->attach($history);
  219. }
  220. $kpd = Compound::where('kpd', $request->kp)->first();
  221. $department = Department::where('_id',$kpd->jbkod)->first();
  222. $faulty = Faulty::where('_id',$kpd->seksyen_kesalahan)->first();
  223. $akta = DeedLaw::where('_id',$faulty->deed_law_id)->first();
  224. $data = [
  225. "_id" => $kpd->_id,
  226. "kpd"=> $kpd->kpd,
  227. "nama"=> $kpd->nama,
  228. "identity" => $kpd->identity,
  229. "nama_syarikat" => $kpd->nama_syarikat,
  230. "no_daftar_syarikat" => $kpd->no_daftar_syarikat,
  231. "alamat" => $kpd->alamat,
  232. "no_plate" => $kpd->no_plate,
  233. "latlong" => $kpd->latlong,
  234. "jbkod" => $department->jnama,
  235. "akta" => "[".$akta->akkod."] ".$akta->nama,
  236. "seksyen_kesalahan" => "[".$faulty->sketr."] ".$faulty->nama,
  237. "jumlah_asal_kompaun" => $kpd->jumlah_asal_kompaun,
  238. "jumlah_kemaskini_kompaun" => $kpd->jumlah_kemaskini_kompaun,
  239. "amount_payment" => $kpd->amount_payment,
  240. "receipt" => $kpd->receipt,
  241. "dikeluarkan" => $kpd->dikeluarkan,
  242. "status" => $kpd->status,
  243. "updated_at" => $kpd->updated_at->toDateTimeString(),
  244. "created_at" => $kpd->created_at->toDateTimeString(),
  245. ];
  246. return $this->sendResponse($data, 'Successfully update compound status');
  247. }else{
  248. return $this->sendResponse('', 'This compound already been paid');
  249. }
  250. }else{
  251. return $this->sendError('Record compound not found!', '');
  252. }
  253. }else{
  254. return $this->sendError('Invalid Api Key', '');
  255. }
  256. }else{
  257. return $this->sendError('Invalid Api Key', '');
  258. }
  259. }
  260. public function compoundToEPBT()
  261. {
  262. $compound = Compound::with('Department','DeedLaw','Faulty','StaffDetail')->where('jenis', 'Pelbagai_JPB')->get();
  263. if(!empty($compound))
  264. {
  265. $data = [];
  266. foreach ($compound as $key => $c)
  267. {
  268. if($c->jenis == 'Pelbagai_KT')
  269. {
  270. $data = [
  271. 'no_kom' => $c->kpd,
  272. 'jenis' => $c->jenis,
  273. 'nama' => $c->nama,
  274. 'no_ic' => $c->identity,
  275. 'no_tel' => $c->no_telefon,
  276. 'nama_syarikat' => $c->nama_syarikat,
  277. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  278. 'no_akaun_lesen' => $c->no_akaun_lesen,
  279. 'alamat' => $c->alamat,
  280. 'jabatan' => $c->Department->jnama,
  281. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  282. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  283. 'catatan' => $c->catatan,
  284. 'latlong' => $c->latlong,
  285. 'status' =>$c->status,
  286. 'amaun_bayar' => $c->amount_payment,
  287. 'receipt' => $c->receipt,
  288. ];
  289. }
  290. if($c->jenis == 'Pelbagai_JPB')
  291. {
  292. $data = [
  293. 'no_kom' => $c->kpd,
  294. 'jenis' => $c->jenis,
  295. 'nama' => $c->nama,
  296. 'no_ic' => $c->identity,
  297. 'no_tel' => $c->no_telefon,
  298. 'nama_syarikat' => $c->nama_syarikat,
  299. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  300. 'no_akaun_lesen' => $c->no_akaun_lesen,
  301. 'alamat' => $c->alamat,
  302. 'jabatan' => $c->Department->jnama,
  303. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  304. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  305. 'catatan' => $c->catatan,
  306. 'latlong' => $c->latlong,
  307. 'status' =>$c->status,
  308. 'amaun_bayar' => $c->amount_payment,
  309. 'receipt' => $c->receipt,
  310. ];
  311. }
  312. if($c->jenis == 'Pelbagai_PA')
  313. {
  314. $data = [
  315. 'no_kom' => $c->kpd,
  316. 'jenis' => $c->jenis,
  317. 'nama' => $c->nama,
  318. 'no_ic' => $c->identity,
  319. 'no_tel' => $c->no_telefon,
  320. 'nama_syarikat' => $c->nama_syarikat,
  321. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  322. 'no_akaun_lesen' => $c->no_akaun_lesen,
  323. 'alamat' => $c->alamat,
  324. 'jabatan' => $c->Department->jnama,
  325. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  326. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  327. 'bil_haiwan' => $c->bil_haiwan,
  328. 'catatan' => $c->catatan,
  329. 'latlong' => $c->latlong,
  330. 'status' =>$c->status,
  331. 'amaun_bayar' => $c->amount_payment,
  332. 'receipt' => $c->receipt,
  333. ];
  334. }
  335. if($c->jenis == 'Pelbagai_LESEN')
  336. {
  337. $data = [
  338. 'no_kom' => $c->kpd,
  339. 'jenis' => $c->jenis,
  340. 'nama' => $c->nama,
  341. 'no_ic' => $c->identity,
  342. 'no_tel' => $c->no_telefon,
  343. 'nama_syarikat' => $c->nama_syarikat,
  344. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  345. 'no_akaun_lesen' => $c->no_akaun_lesen,
  346. 'alamat' => $c->alamat,
  347. 'jabatan' => $c->Department->jnama,
  348. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  349. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  350. 'catatan' => $c->catatan,
  351. 'latlong' => $c->latlong,
  352. 'status' =>$c->status,
  353. 'amaun_bayar' => $c->amount_payment,
  354. 'receipt' => $c->receipt,
  355. ];
  356. }
  357. if($c->jenis == 'Parkir')
  358. {
  359. $data = [
  360. 'no_kom' => $c->kpd,
  361. 'jenis' => $c->jenis,
  362. 'nama' => $c->nama,
  363. 'no_ic' => $c->identity,
  364. 'no_tel' => $c->no_telefon,
  365. 'nama_syarikat' => $c->nama_syarikat,
  366. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  367. 'no_akaun_lesen' => $c->no_akaun_lesen,
  368. 'alamat' => $c->alamat,
  369. 'jabatan' => $c->Department->jnama,
  370. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  371. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  372. 'catatan' => $c->catatan,
  373. 'latlong' => $c->latlong,
  374. 'status' =>$c->status,
  375. 'amaun_bayar' => $c->amount_payment,
  376. 'receipt' => $c->receipt,
  377. ];
  378. }
  379. }
  380. return $this->sendResponse($data, 'Successfully update compound status');
  381. }
  382. }
  383. }