Dashboard sipadu mbip
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

RestfulapiController.php 18KB

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