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

RestfulapiController.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. namespace App\Http\Controllers\api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Api\BaseController;
  5. use Carbon\Carbon;
  6. use App\Model\Staff;
  7. use App\Model\StaffDetail;
  8. use App\Model\User;
  9. use App\Model\UserDetail;
  10. use App\Model\Module\Roles;
  11. use App\Model\Module\Compound;
  12. use App\Model\Module\Department;
  13. use App\Model\Module\DeedLaw;
  14. use App\Model\Module\Faulty;
  15. use App\Model\Module\ConfidentialFile;
  16. use App\Model\Module\History;
  17. use App\Model\Module\Memo;
  18. use App\Model\Module\Attachment;
  19. use App\Model\Module\ApiIntegration;
  20. use App\Jobs\StoreCompound;
  21. use App\Jobs\UpdateCompoundPrice;
  22. class RestfulapiController extends BaseController
  23. {
  24. /**
  25. * Create search compound by category controller.
  26. *
  27. * @return json
  28. */
  29. public function searchIdentity($request){
  30. $compound = Compound::with('Faulty','Department','DeedLaw')->where('identity',$request)->get();
  31. return $compound;
  32. }
  33. public function searchKpd($request){
  34. $compound = Compound::with('Faulty','Department','DeedLaw')->where('kpd','like',$request)->get();
  35. return $compound;
  36. }
  37. public function searchSyarikat($request){
  38. $compound = Compound::with('Faulty','Department','DeedLaw')->where('no_daftar_syarikat','like',$request)->get();
  39. return $compound;
  40. }
  41. public function searchPlate($request){
  42. $compound = Compound::with('Faulty','Department','DeedLaw')->where('no_plate','like',$request)->get();
  43. return $compound;
  44. }
  45. /**
  46. * Create search compound controller.
  47. *
  48. * @return json
  49. */
  50. public function viewCompoundPersonal(Request $request)
  51. {
  52. $compound = array();
  53. $search = $request->search;
  54. $api_integrasi = ApiIntegration::where('key', $request->key)->first();
  55. if(!empty($api_integrasi)){
  56. if($api_integrasi->status == 'active'){
  57. if($search != '' && $search != '-'){
  58. if(count($this->searchIdentity($search)) > 0){
  59. $compound = $this->searchIdentity($search);
  60. }
  61. if(count($this->searchKpd($search)) > 0){
  62. $compound = $this->searchKpd($search);
  63. }
  64. if(count($this->searchSyarikat($search)) > 0){
  65. $compound = $this->searchSyarikat($search);
  66. }
  67. if(count($this->searchPlate($search)) > 0){
  68. $compound = $this->searchPlate($search);
  69. }
  70. $data = array();
  71. if(count($compound) > 0){
  72. foreach($compound as $c){
  73. // $department = Department::where('_id',$c->jbkod)->first();
  74. // $faulty = Faulty::where('_id',$c->seksyen_kesalahan)->first();
  75. // $akta = DeedLaw::where('_id',$faulty->deed_law_id)->first();
  76. if($c->jenis == 'Pelbagai'){
  77. array_push($data,array(
  78. "_id" => $c->_id,
  79. "jenis" => $c->jenis,
  80. "kpd"=> $c->kpd,
  81. "nama"=> $c->nama,
  82. "identity" => $c->identity,
  83. "nama_syarikat" => $c->nama_syarikat,
  84. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat),
  85. "alamat" => $c->alamat,
  86. "no_plate" => strtoupper($c->no_plate),
  87. "no_cukai_jalan" => $c->no_cukai_jalan,
  88. "latlong" => $c->latlong,
  89. "jbkod" => $c->Department->jnama,
  90. "akta" => $c->DeedLaw->nama,
  91. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  92. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  93. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  94. "amount_payment" => $c->amount_payment,
  95. "receipt" => $c->receipt,
  96. "dikeluarkan" => $c->dikeluarkan,
  97. "status" => $c->status,
  98. "updated_at" => $c->updated_at->toDateTimeString(),
  99. "created_at" => $c->created_at->toDateTimeString(),
  100. ));
  101. }else if($c->jenis == 'Parkir'){
  102. array_push($data,array(
  103. "_id" => $c->_id,
  104. "jenis" => $c->jenis,
  105. "kpd"=> $c->kpd,
  106. "no_plate" => strtoupper($c->no_plate),
  107. "no_cukai_jalan" => $c->no_cukai_jalan,
  108. "jenis_kenderaan" => $c->jenis_kenderaan,
  109. "model_kenderaan" => $c->model_kenderaan,
  110. "warna_kenderaan" => $c->warna_kenderaan,
  111. "nama_taman" => $c->nama_taman,
  112. "nama_jalan" => $c->nama_jalan,
  113. "no_parking" => $c->no_parking,
  114. "latlong" => $c->latlong,
  115. "jbkod" => $c->Department->jnama,
  116. "akta" => $c->DeedLaw->nama,
  117. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  118. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  119. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  120. "amount_payment" => $c->amount_payment,
  121. "receipt" => $c->receipt,
  122. "dikeluarkan" => $c->dikeluarkan,
  123. "status" => $c->status,
  124. "updated_at" => $c->updated_at->toDateTimeString(),
  125. "created_at" => $c->created_at->toDateTimeString(),
  126. ));
  127. }
  128. }
  129. return $this->sendResponse($data, 'Result Found');
  130. }else {
  131. return $this->sendResponse('', 'No Result');
  132. }
  133. }else{
  134. return $this->sendError('Search field is compulsory!', '');
  135. }
  136. }else{
  137. return $this->sendError('Invalid Api Key', '');
  138. }
  139. }else{
  140. return $this->sendError('Invalid Api Key', '');
  141. }
  142. }
  143. /**
  144. * Create update compound controller.
  145. *
  146. * @return json
  147. */
  148. public function updatePaymentIntegrasi(Request $request){
  149. $api_integrasi = ApiIntegration::where('key', $request->key)->first();
  150. if(!empty($api_integrasi)){
  151. if($api_integrasi->status == 'active'){
  152. $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kp)->first();
  153. if(!empty($compound)){
  154. if($compound->status != 'Berbayar'){
  155. $compound->status = 'Berbayar';
  156. $compound->receipt = $request->receipt;
  157. $compound->amount_payment = $request->amount;
  158. $compound->save();
  159. $now = Carbon::now();
  160. $gDate = $now->format('F Y');
  161. $historyData = [
  162. 'tarikh_kumpulan' => $gDate,
  163. ];
  164. $subHistory = [
  165. 'no_siri' => $compound->ConfidentialFile->no_siri,
  166. 'tajuk' => "Pembayaran kompaun ".$request->orderid." telah dibuat secara 'online'",
  167. 'huraian' => "Pembayaran kompaun ".$request->orderid." telah dijelaskan pada hari ini.",
  168. ];
  169. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  170. if(!empty($groupByDate)){
  171. $groupByDate->subhistory()->create($subHistory);
  172. $compound->ConfidentialFile->history()->attach($groupByDate);
  173. }else{
  174. $history = History::create($historyData);
  175. $history->subhistory()->create($subHistory);
  176. $compound->ConfidentialFile->history()->attach($history);
  177. }
  178. $kpd = Compound::where('kpd', $request->kp)->first();
  179. $department = Department::where('_id',$kpd->jbkod)->first();
  180. $faulty = Faulty::where('_id',$kpd->seksyen_kesalahan)->first();
  181. $akta = DeedLaw::where('_id',$faulty->deed_law_id)->first();
  182. $data = [
  183. "_id" => $kpd->_id,
  184. "kpd"=> $kpd->kpd,
  185. "nama"=> $kpd->nama,
  186. "identity" => $kpd->identity,
  187. "nama_syarikat" => $kpd->nama_syarikat,
  188. "no_daftar_syarikat" => $kpd->no_daftar_syarikat,
  189. "alamat" => $kpd->alamat,
  190. "no_plate" => $kpd->no_plate,
  191. "latlong" => $kpd->latlong,
  192. "jbkod" => $department->jnama,
  193. "akta" => "[".$akta->akkod."] ".$akta->nama,
  194. "seksyen_kesalahan" => "[".$faulty->sketr."] ".$faulty->nama,
  195. "jumlah_asal_kompaun" => $kpd->jumlah_asal_kompaun,
  196. "jumlah_kemaskini_kompaun" => $kpd->jumlah_kemaskini_kompaun,
  197. "amount_payment" => $kpd->amount_payment,
  198. "receipt" => $kpd->receipt,
  199. "dikeluarkan" => $kpd->dikeluarkan,
  200. "status" => $kpd->status,
  201. "updated_at" => $kpd->updated_at->toDateTimeString(),
  202. "created_at" => $kpd->created_at->toDateTimeString(),
  203. ];
  204. return $this->sendResponse($data, 'Successfully update compound status');
  205. }else{
  206. return $this->sendResponse('', 'This compound already been paid');
  207. }
  208. }else{
  209. return $this->sendError('Record compound not found!', '');
  210. }
  211. }else{
  212. return $this->sendError('Invalid Api Key', '');
  213. }
  214. }else{
  215. return $this->sendError('Invalid Api Key', '');
  216. }
  217. }
  218. }