Dashboard sipadu mbip
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

RestfulapiController.php 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. // $date = Carbon::createFromFormat('Y-m-d', $request->date)->toDateString();
  73. $compound = Compound::with('Faulty', 'Department', 'DeedLaw')->where('jenis', $jenis)->orWhere('jenis_n', $jenis)
  74. ->orWhere(function($q) use
  75. ($notice, $ic, $date, $jalan, $taman, $kawasan) {
  76. if(!empty($notice) && $notice != '-'){
  77. $q = $q->where('non', $notice)->orWhere('kpd', $notice);
  78. }
  79. if(!empty($ic) && $ic != '-'){
  80. $q = $q->where('identity', $ic);
  81. }
  82. if(!empty($date)){
  83. $start = Carbon::createFromFormat('Y-m-d', $date)->startOfDay();
  84. $end = Carbon::createFromFormat('Y-m-d', $date)->endOfDay();
  85. $q = $q->whereBetween('created_at', [$start, $end]);
  86. }
  87. })->get();
  88. }
  89. else if($request->filled('search')){
  90. $search = $request->search;
  91. $compound = Compound::with('Faulty','Department','DeedLaw')->where('kpd','like',$search)->orWhere('non', 'like', $search)
  92. ->orWhere('no_daftar_syarikat', $search)->orWhere('no_plate', $search)->orWhere('identity', $search)->get();
  93. }
  94. else{
  95. return $this->sendError('Could not search!', '');
  96. }
  97. if(count($compound) > 0){
  98. $data = array();
  99. $all_data = array();
  100. foreach($compound as $c){
  101. //check compound & notice created and convert to date & time
  102. $tarikh_n = '-'; $masa_n = '-'; $tarikh = '-'; $masa = '-';
  103. if (!empty($c->created_n))
  104. {
  105. $tarikh_n = Carbon::parse($c->created_c)->format("D, d M, 'y");
  106. $masa_n = Carbon::parse($c->created_c)->format("g:i A");
  107. }
  108. if(!empty($c->created_c))
  109. {
  110. $tarikh = Carbon::parse($c->created_n)->format("D, d M, 'y");
  111. $masa = Carbon::parse($c->created_n)->format("g:i A");
  112. }
  113. //set default data to '-' if not present
  114. array_push($data,array(
  115. "_id" => $c->_id ,
  116. "non" => $c->non ?? '-',
  117. "jenis_notis" => $c->jenis_n ?? '-',
  118. "kpd"=> $c->kpd ?? '-',
  119. "jenis_kompaun" => $c->jenis ?? '-',
  120. "nama"=> $c->nama ?? '-',
  121. "identity" => $c->identity ?? '-',
  122. "no_tel" => $c->no_tel ?? '-',
  123. "nama_syarikat" => $c->nama_syarikat ?? '-',
  124. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat) ?? '-',
  125. "no_akaun_lesen" => $c->no_akaun_lesen ?? '-',
  126. "alamat" => $c->alamat ?? '-',
  127. "no_plate" => strtoupper($c->no_plate) ?? '-',
  128. "no_cukai_jalan" => $c->no_cukai_jalan ?? '-',
  129. "latlong" => $c->latlong ?? '-',
  130. "nama_kawasan" => $c->nama_kawasan ?? '-',
  131. "nama_taman" => $c->nama_taman ?? '-',
  132. "nama_jalan" => $c->nama_jalan ?? '-',
  133. "jbkod" => $c->Department->jnama ?? '-',
  134. "akta_notis" => $c->deedlawNotis->nama ?? '-',
  135. "seksyen_kesalahan_notis" => $c->FaultyNotis->nama ?? '-',
  136. "akta" => $c->DeedLaw->nama ?? '-',
  137. "seksyen_kesalahan" => $c->Faulty->nama ?? '-',
  138. "catatan" => $c->catatan ?? '-',
  139. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun ?? '-',
  140. "amount_payment" => $c->amount_payment ?? '-',
  141. "receipt" => $c->receipt ?? '-',
  142. "notis_dikeluarkan" => $c->dikeluarkan_n ?? '-',
  143. "kompaun_dikeluarkan" => $c->dikeluarkan_n ?? '-',
  144. "status" => $c->status,
  145. "tarikh_notis" => $tarikh_n ,
  146. "masa_notis" => $masa_n ,
  147. "tarikh_kompaun" => $tarikh,
  148. "masa_kompaun" => $masa
  149. ));
  150. array_push($all_data, $data);
  151. }
  152. return $this->sendResponse($data, 'Result Found');
  153. }else {
  154. return $this->sendResponse('', 'No Result');
  155. }
  156. }else{
  157. return $this->sendError('Invalid Api Key', '');
  158. }
  159. }else{
  160. return $this->sendError('Invalid Api Key', '');
  161. }
  162. }
  163. /**
  164. * Create update compound controller.
  165. *
  166. * @return json
  167. */
  168. public function updatePaymentIntegrasi(Request $request){
  169. $api_integrasi = ApiIntegration::where('key', $request->key)->first();
  170. if(!empty($api_integrasi)){
  171. if($api_integrasi->status == 'active'){
  172. $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kp)->first();
  173. if(!empty($compound)){
  174. if($compound->status != 'Berbayar'){
  175. $compound->status = 'Berbayar';
  176. $compound->receipt = $request->receipt;
  177. $compound->amount_payment = $request->amount;
  178. $compound->save();
  179. $now = Carbon::now();
  180. $gDate = $now->format('F Y');
  181. $historyData = [
  182. 'tarikh_kumpulan' => $gDate,
  183. ];
  184. $subHistory = [
  185. 'no_siri' => $compound->ConfidentialFile->no_siri,
  186. 'tajuk' => "Pembayaran kompaun ".$request->orderid." telah dibuat secara 'online'",
  187. 'huraian' => "Pembayaran kompaun ".$request->orderid." telah dijelaskan pada hari ini.",
  188. ];
  189. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  190. if(!empty($groupByDate)){
  191. $groupByDate->subhistory()->create($subHistory);
  192. $compound->ConfidentialFile->history()->attach($groupByDate);
  193. }else{
  194. $history = History::create($historyData);
  195. $history->subhistory()->create($subHistory);
  196. $compound->ConfidentialFile->history()->attach($history);
  197. }
  198. $kpd = Compound::where('kpd', $request->kp)->first();
  199. $department = Department::where('_id',$kpd->jbkod)->first();
  200. $faulty = Faulty::where('_id',$kpd->seksyen_kesalahan)->first();
  201. $akta = DeedLaw::where('_id',$faulty->deed_law_id)->first();
  202. $data = [
  203. "_id" => $kpd->_id,
  204. "kpd"=> $kpd->kpd,
  205. "nama"=> $kpd->nama,
  206. "identity" => $kpd->identity,
  207. "nama_syarikat" => $kpd->nama_syarikat,
  208. "no_daftar_syarikat" => $kpd->no_daftar_syarikat,
  209. "alamat" => $kpd->alamat,
  210. "no_plate" => $kpd->no_plate,
  211. "latlong" => $kpd->latlong,
  212. "jbkod" => $department->jnama,
  213. "akta" => "[".$akta->akkod."] ".$akta->nama,
  214. "seksyen_kesalahan" => "[".$faulty->sketr."] ".$faulty->nama,
  215. "jumlah_asal_kompaun" => $kpd->jumlah_asal_kompaun,
  216. "jumlah_kemaskini_kompaun" => $kpd->jumlah_kemaskini_kompaun,
  217. "amount_payment" => $kpd->amount_payment,
  218. "receipt" => $kpd->receipt,
  219. "dikeluarkan" => $kpd->dikeluarkan,
  220. "status" => $kpd->status,
  221. "updated_at" => $kpd->updated_at->toDateTimeString(),
  222. "created_at" => $kpd->created_at->toDateTimeString(),
  223. ];
  224. return $this->sendResponse($data, 'Successfully update compound status');
  225. }else{
  226. return $this->sendResponse('', 'This compound already been paid');
  227. }
  228. }else{
  229. return $this->sendError('Record compound not found!', '');
  230. }
  231. }else{
  232. return $this->sendError('Invalid Api Key', '');
  233. }
  234. }else{
  235. return $this->sendError('Invalid Api Key', '');
  236. }
  237. }
  238. public function compoundToEPBT()
  239. {
  240. $compound = Compound::with('Department','DeedLaw','Faulty','StaffDetail')->where('jenis', 'Pelbagai_JPB')->get();
  241. if(!empty($compound))
  242. {
  243. $data = [];
  244. foreach ($compound as $key => $c)
  245. {
  246. if($c->jenis == 'Pelbagai_KT')
  247. {
  248. $data = [
  249. 'no_kom' => $c->kpd,
  250. 'jenis' => $c->jenis,
  251. 'nama' => $c->nama,
  252. 'no_ic' => $c->identity,
  253. 'no_tel' => $c->no_telefon,
  254. 'nama_syarikat' => $c->nama_syarikat,
  255. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  256. 'no_akaun_lesen' => $c->no_akaun_lesen,
  257. 'alamat' => $c->alamat,
  258. 'jabatan' => $c->Department->jnama,
  259. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  260. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  261. 'catatan' => $c->catatan,
  262. 'latlong' => $c->latlong,
  263. 'status' =>$c->status,
  264. 'amaun_bayar' => $c->amount_payment,
  265. 'receipt' => $c->receipt,
  266. ];
  267. }
  268. if($c->jenis == 'Pelbagai_JPB')
  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_PA')
  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. 'bil_haiwan' => $c->bil_haiwan,
  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_LESEN')
  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. '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 == 'Parkir')
  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. }
  358. return $this->sendResponse($data, 'Successfully update compound status');
  359. }
  360. }
  361. }