Dashboard sipadu mbip
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RestfulapiController.php 19KB

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