Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompoundResourceController.php 45KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  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\Module\Compound;
  9. use App\Model\Module\Department;
  10. use App\Model\Module\DeedLaw;
  11. use App\Model\Module\Faulty;
  12. use App\Model\Module\ConfidentialFile;
  13. use App\Model\Module\History;
  14. use App\Model\Module\SubHistory;
  15. use App\Model\Module\Memo;
  16. use App\Model\Module\Attachment;
  17. use App\Jobs\StoreCompound;
  18. use App\Jobs\StoreCompoundEPBT;
  19. use App\Jobs\UpdateCompoundPrice;
  20. use App\Http\Resources\CompoundResource;
  21. class CompoundResourceController extends BaseController
  22. {
  23. /**
  24. * @var ServiceCategory
  25. */
  26. protected $compound;
  27. /**
  28. * ServiceController constructor.
  29. *
  30. * @param ServiceCategory $ServiceCategory
  31. */
  32. public function __construct(Compound $compound)
  33. {
  34. $this->compound = $compound;
  35. }
  36. /**
  37. * Display a listing of the resource.
  38. *
  39. * @return \Illuminate\Http\Response
  40. */
  41. private function searchCompoundAll($jenis,$modul,$status,$start_date,$end_date){
  42. $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
  43. $start = $dateS->copy()->startOfDay();
  44. if($end_date != ''){
  45. $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
  46. $end = $dateE->copy()->endOfDay();
  47. }else{
  48. $end = $dateS->copy()->endOfDay();
  49. }
  50. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start, $end));
  51. if($modul == 'All'){
  52. $compound = $compound;
  53. }else if($modul == '06-07'){
  54. $compound = $compound->where(function($q){
  55. $q->where(function($query){
  56. $query->where('modul', '06')->orWhere('modul','07');
  57. });
  58. });
  59. }else {
  60. $compound = $compound->where('modul', $modul);
  61. }
  62. if($status == 'All'){
  63. $compound = $compound;
  64. }else {
  65. $compound = $compound->where('status', $status);
  66. }
  67. return $compound;
  68. }
  69. private function searchCompoundAllWithoutDate($jenis,$modul,$status){
  70. $compound = Compound::where('jenis', $jenis);
  71. if($modul == 'All'){
  72. $compound = $compound;
  73. }else if($modul == '06-07'){
  74. $compound = $compound->where(function($q){
  75. $q->where(function($query){
  76. $query->where('modul', '06')->orWhere('modul','07');
  77. });
  78. });
  79. }else {
  80. $compound = $compound->where('modul', $modul);
  81. }
  82. if($status == 'All'){
  83. $compound = $compound;
  84. }else {
  85. $compound = $compound->where('status', $status);
  86. }
  87. return $compound;
  88. }
  89. private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date){
  90. if(!empty($start_date)){
  91. $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date);
  92. }else{
  93. $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status);
  94. }
  95. if($enforcer == 'All'){
  96. return $compound;
  97. }else {
  98. $compound = $compound->where('dikeluarkan', $enforcer);
  99. return $compound;
  100. }
  101. }
  102. private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department){
  103. $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date);
  104. if($faulty == 'All'){
  105. return $compound->whereIn('jbkod',$department);
  106. }else {
  107. $compound = $compound->where('seksyen_kesalahan', $faulty);
  108. return $compound;
  109. }
  110. }
  111. private function searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no){
  112. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department);
  113. if(!empty($plate_no)){
  114. $compound = $compound->where('no_plate',$plate_no);
  115. return $compound;
  116. }else{
  117. return $compound;
  118. }
  119. }
  120. private function searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd){
  121. $compound = $this->searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no);
  122. if(!empty($kpd)){
  123. $compound = $compound->where('kpd',$kpd);
  124. return $compound;
  125. }else{
  126. $compound = $compound->whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal']);
  127. return $compound;
  128. }
  129. }
  130. private function searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no){
  131. $compound = $this->searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd);
  132. if(!empty($company_no)){
  133. $compound = $compound->where('no_daftar_syarikat','LIKE',$company_no);
  134. return $compound;
  135. }else{
  136. return $compound;
  137. }
  138. }
  139. private function searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric){
  140. $compound = $this->searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no);
  141. if(!empty($nric)){
  142. $compound = $compound->where('identity',$nric);
  143. return $compound;
  144. }else{
  145. return $compound;
  146. }
  147. }
  148. private function searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license){
  149. $compound = $this->searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric);
  150. if(!empty($license)){
  151. $compound = $compound->where('no_akaun_lesen', 'exists', true)->where('no_akaun_lesen',$license);
  152. return $compound;
  153. }else{
  154. return $compound;
  155. }
  156. }
  157. private function searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP){
  158. $compound = $this->searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license);
  159. if(!empty($namaP)){
  160. $compound = $compound->where('nama', 'LIKE', "%{$namaP}%");
  161. return $compound;
  162. }else{
  163. return $compound;
  164. }
  165. }
  166. private function searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name){
  167. $compound = $this->searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP);
  168. if(!empty($company_name)){
  169. $compound = $compound->where('nama_syarikat', 'exists', true)->where('nama_syarikat', 'LIKE', '%{$company_name%}');
  170. return $compound;
  171. }else{
  172. return $compound;
  173. }
  174. }
  175. public function index(Request $request)
  176. {
  177. // $per_page = '';
  178. // $kpd = '';
  179. // $modul = 'All';
  180. // $status = 'All';
  181. // $jenis = 'Pelbagai_JPB';
  182. // if(!empty($request->department)){
  183. // $department = ["5df721c5cde7fd741433c6b2","5d957899f3da686c08192026","5d9d4a699b802d5a31031a8a","5d9d4db1aa95fa07f7245e28","5d9d5955eb4f92300927f188","5d9e965fec0023467756a02a","5d9eba38e4be2267877896a8"];
  184. // }else {
  185. // $department = [];
  186. // }
  187. // $start_date = '2020-07-18';
  188. // $end_date = '2020-08-14';
  189. // $enforcer = 'All';
  190. // $faulty = 'All';
  191. // $plate_no = strtolower('');
  192. // $company_no = strtolower('');
  193. // $nric = '';
  194. // $license = '';
  195. // $namaP = '';
  196. // $company_name = '';
  197. /////////////////////////////////////////////////////////////////////////////////
  198. $per_page = $request->per_page;
  199. $kpd = $request->kpd;
  200. $modul = $request->modul;
  201. $status = $request->status;
  202. $jenis = $request->type;
  203. if(!empty($request->department)){
  204. $department = json_decode($request->department);
  205. }else {
  206. $department = [];
  207. }
  208. $start_date = $request->start_date;
  209. $end_date = $request->end_date;
  210. $enforcer = $request->enforcer;
  211. $faulty = $request->faulty;
  212. $plate_no = strtolower($request->plate_no);
  213. $company_no = strtolower($request->company_no);
  214. $nric = $request->nric;
  215. $license = $request->license;
  216. $namaP = $request->nameP;
  217. $company_name = $request->company_name;
  218. $nested_data = array();
  219. $compound = $this->searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name)->orderBy('created_at','ASC')->get();
  220. return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
  221. ->addColumn('index', function($row) {
  222. $curr = Carbon::now();
  223. $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
  224. if($curr->diffInDays($dtC) <= 3){
  225. $html = 'New';
  226. }else{ $html = ''; }
  227. return $html;
  228. })->addColumn('status_kemaskini', function($row) {
  229. $data = '';
  230. if($row['status'] == 'Berbayar'){
  231. $data = '<b>'.$row['status'].'</b><div style="margin-top: 8px"><span>Bayaran: </span><br/>';
  232. $data .= 'RM '.$row['amount_payment'].'</div>';
  233. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  234. if($row['updated_by'] !== null ){
  235. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  236. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  237. }else {
  238. if(!empty($row['tarikh_bayar']) && $row['tarikh_bayar'] != ''){
  239. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  240. $data .= $row['tarikh_bayar'].' <br/>'.$row['updates_by'].'</div>';
  241. }else {
  242. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  243. $data .= $row['updated_at'].' <br/>'.$row['updates_by'].'</div>';
  244. }
  245. }
  246. }else if($row['status'] == 'Belum Bayar' && $row['updated_by'] !== null){
  247. $data = '<b>'.$row['status'].'</b>';
  248. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  249. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  250. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  251. }else if($row['status'] == 'Batal' && $row['updated_by'] !== null){
  252. $data = '<b>'.$row['status'].'</b>';
  253. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  254. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  255. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  256. }else if($row['status'] == 'Buang' && $row['updated_by'] !== null){
  257. $data = '<b>'.$row['status'].'</b>';
  258. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  259. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  260. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  261. }
  262. else
  263. {
  264. $data = $row['status'];
  265. }
  266. return $data;
  267. })->addColumn('kesalahan', function($row) {
  268. $data = '<b>Seksyen '.$row['faulty_skter'].'</b><br/>'.$row['faulty_name'];
  269. return $data;
  270. })->rawColumns(['index','status_kemaskini','kesalahan'])->make(true);
  271. }
  272. /**
  273. * Show the form for creating a new resource.
  274. *
  275. * @return \Illuminate\Http\Response
  276. */
  277. public function create()
  278. {
  279. //
  280. }
  281. /**
  282. * Store a newly created resource in storage.
  283. *
  284. * @param \Illuminate\Http\Request $request
  285. * @return \Illuminate\Http\Response
  286. */
  287. public function store(Request $request)
  288. {
  289. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  290. if(empty($staff)){
  291. return $this->sendError('Invalid', 'Staff not existed');
  292. }else {
  293. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  294. if(!empty($faulty)){
  295. $data = array();
  296. $countKPD = $this->compound->withTrashed()->count();
  297. do {
  298. $countKPD = $countKPD + 1;
  299. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  300. $kpd = 'KP' . $countKPD;
  301. $no_siri = date('yn').'-'.$countKPD;
  302. $fileData = [
  303. 'no_siri' => $no_siri,
  304. ];
  305. if($request->jenis == 'Parkir'){
  306. $compoundData = [
  307. 'jenis' => 'Parkir',
  308. 'kpd' => $kpd,
  309. 'nama' => '-',
  310. 'identity' => '-',
  311. 'alamat' => '-',
  312. "no_plate" => strtolower($request->no_plate),
  313. "no_cukai_jalan" => $request->noCukaijalan,
  314. "jenis_kenderaan" => $request->jenisKenderaan,
  315. "model_kenderaan" => $request->modelKenderaan,
  316. "warna_kenderaan" => $request->warnakenderaan,
  317. "nama_kawasan" => $request->namaKawasan,
  318. "nama_taman" => $request->namaTaman,
  319. "nama_jalan" => $request->namaJalan,
  320. "no_parking" => $request->noParking,
  321. "catatan" => $request->catatan,
  322. "lokasi_kejadian" => '-',
  323. 'latlong' => $request->Latlong,
  324. 'jbkod' => $request->jabatan,
  325. 'akta' => $faulty->deed_law_id,
  326. 'seksyen_kesalahan' => $faulty->_id,
  327. 'jumlah_asal_kompaun' => $faulty->amount,
  328. 'jumlah_kemaskini_kompaun' => '',
  329. 'dikeluarkan' => $staff->_id,
  330. "status" => 'Belum Bayar',
  331. "amount_payment" => '',
  332. "receipt" => '',
  333. "modul" => '03',
  334. "penguatkuasa" => '',
  335. ];
  336. }elseif($request->jenis == 'Pelbagai_KT'){
  337. $compoundData = [
  338. 'jenis' => $request->jenis,
  339. 'kpd' => $kpd,
  340. 'nama' => $request->namaP,
  341. 'identity' => $request->noIc,
  342. 'nama_syarikat' => $request->namaS,
  343. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  344. 'alamat' => $request->alamat,
  345. "no_plate" => $request->no_plate,
  346. "no_cukai_jalan" => $request->no_cukai_jalan,
  347. "nama_kawasan" => $request->namaKawasan,
  348. "nama_taman" => $request->namaTaman,
  349. "nama_jalan" => $request->namaJalan,
  350. "catatan" => $request->catatan,
  351. "lokasi_kejadian" => '-',
  352. 'latlong' => $request->Latlong,
  353. 'jbkod' => $request->jabatan,
  354. 'akta' => $faulty->deed_law_id,
  355. 'seksyen_kesalahan' => $faulty->_id,
  356. 'jumlah_asal_kompaun' => $faulty->amount,
  357. 'jumlah_kemaskini_kompaun' => '',
  358. 'dikeluarkan' => $staff->_id,
  359. "status" => 'Belum Bayar',
  360. "amount_payment" => '',
  361. "receipt" => '',
  362. "modul" => '03',
  363. "penguatkuasa" => '',
  364. "no_telefon" => $request->tel,
  365. "no_akaun_lesen" => $request->lesen,
  366. "maklumat_tambahan" => '-',
  367. ];
  368. }elseif($request->jenis == 'Pelbagai_JPB'){
  369. $compoundData = [
  370. 'jenis' => $request->jenis,
  371. 'kpd' => $kpd,
  372. 'nama' => $request->namaP,
  373. 'identity' => $request->noIc,
  374. 'nama_syarikat' => $request->namaS,
  375. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  376. 'alamat' => $request->alamat,
  377. "no_plate" => $request->no_plate,
  378. "no_cukai_jalan" => $request->no_cukai_jalan,
  379. "nama_kawasan" => $request->namaKawasan,
  380. "nama_taman" => $request->namaTaman,
  381. "nama_jalan" => $request->namaJalan,
  382. "catatan" => $request->catatan,
  383. "lokasi_kejadian" => '-',
  384. 'latlong' => $request->Latlong,
  385. 'jbkod' => $request->jabatan,
  386. 'akta' => $faulty->deed_law_id,
  387. 'seksyen_kesalahan' => $faulty->_id,
  388. 'jumlah_asal_kompaun' => $faulty->amount,
  389. 'jumlah_kemaskini_kompaun' => '',
  390. 'dikeluarkan' => $staff->_id,
  391. "status" => 'Belum Bayar',
  392. "amount_payment" => '',
  393. "receipt" => '',
  394. "modul" => '03',
  395. "penguatkuasa" => '',
  396. "no_telefon" => $request->tel,
  397. "no_akaun_lesen" => $request->lesen,
  398. "maklumat_tambahan" => '-',
  399. ];
  400. }elseif($request->jenis == 'Pelbagai_PA'){
  401. $compoundData = [
  402. 'jenis' => $request->jenis,
  403. 'kpd' => $kpd,
  404. 'nama' => $request->namaP,
  405. 'identity' => $request->noIc,
  406. 'nama_syarikat' => $request->namaS,
  407. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  408. 'alamat' => $request->alamat,
  409. "no_plate" => $request->no_plate,
  410. "no_cukai_jalan" => $request->no_cukai_jalan,
  411. "nama_kawasan" => $request->namaKawasan,
  412. "nama_taman" => $request->namaTaman,
  413. "nama_jalan" => $request->namaJalan,
  414. "catatan" => $request->catatan,
  415. "lokasi_kejadian" => '-',
  416. 'latlong' => $request->Latlong,
  417. 'jbkod' => $request->jabatan,
  418. 'akta' => $faulty->deed_law_id,
  419. 'seksyen_kesalahan' => $faulty->_id,
  420. 'jumlah_asal_kompaun' => $faulty->amount,
  421. 'jumlah_kemaskini_kompaun' => '',
  422. 'dikeluarkan' => $staff->_id,
  423. "status" => 'Belum Bayar',
  424. "amount_payment" => '',
  425. "receipt" => '',
  426. "modul" => '03',
  427. "penguatkuasa" => '',
  428. "no_telefon" => $request->tel,
  429. "no_akaun_lesen" => $request->lesen,
  430. "maklumat_tambahan" => '-',
  431. ];
  432. }
  433. elseif($request->jenis == 'Pelbagai_LESEN'){
  434. $compoundData = [
  435. 'jenis' => $request->jenis,
  436. 'kpd' => $kpd,
  437. 'nama' => $request->namaP,
  438. 'identity' => $request->noIc,
  439. 'nama_syarikat' => $request->namaS,
  440. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  441. 'alamat' => $request->alamat,
  442. "no_plate" => $request->no_plate,
  443. "no_cukai_jalan" => $request->no_cukai_jalan,
  444. "nama_kawasan" => $request->namaKawasan,
  445. "nama_taman" => $request->namaTaman,
  446. "nama_jalan" => $request->namaJalan,
  447. "catatan" => $request->catatan,
  448. "lokasi_kejadian" => '-',
  449. 'latlong' => $request->Latlong,
  450. 'jbkod' => $request->jabatan,
  451. 'akta' => $faulty->deed_law_id,
  452. 'seksyen_kesalahan' => $faulty->_id,
  453. 'jumlah_asal_kompaun' => $faulty->amount,
  454. 'jumlah_kemaskini_kompaun' => '',
  455. 'dikeluarkan' => $staff->_id,
  456. "status" => 'Belum Bayar',
  457. "amount_payment" => '',
  458. "receipt" => '',
  459. "modul" => '03',
  460. "penguatkuasa" => '',
  461. "no_telefon" => $request->tel,
  462. "no_akaun_lesen" => $request->lesen,
  463. "maklumat_tambahan" => '-',
  464. ];
  465. }
  466. $file = ConfidentialFile::create($fileData);
  467. $saved = $file->compound()->create($compoundData);
  468. if($saved){
  469. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  470. // if(!empty($compound)){
  471. dispatch(new UpdateCompoundPrice($kpd));
  472. // $tawaran = '';
  473. // if($compound->jumlah_kemaskini_kompaun != ''){
  474. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  475. // }else{
  476. // $tawaran = $compound->jumlah_asal_kompaun;
  477. // }
  478. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  479. array_push($data, array('kpd' => $kpd));
  480. // $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  481. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  482. // }
  483. }
  484. }
  485. }
  486. }
  487. public function storeNotice(Request $request)
  488. {
  489. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  490. if(empty($staff)){
  491. return $this->sendError('Invalid', 'Staff not existed');
  492. }else {
  493. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  494. if(!empty($faulty)){
  495. $data = array();
  496. $countKPD = $this->compound->withTrashed()->count();
  497. do {
  498. $countKPD = $countKPD + 1;
  499. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  500. $kpd = 'KP' . $countKPD;
  501. $no_siri = date('yn').'-'.$countKPD;
  502. $fileData = [
  503. 'no_siri' => $no_siri,
  504. ];
  505. if($request->jenis == 'Parkir'){
  506. $compoundData = [
  507. 'jenis' => 'Parkir',
  508. 'kpd' => $kpd,
  509. 'nama' => '-',
  510. 'identity' => '-',
  511. 'alamat' => '-',
  512. "no_plate" => strtolower($request->no_plate),
  513. "no_cukai_jalan" => $request->noCukaijalan,
  514. "jenis_kenderaan" => $request->jenisKenderaan,
  515. "model_kenderaan" => $request->modelKenderaan,
  516. "warna_kenderaan" => $request->warnakenderaan,
  517. "nama_kawasan" => $request->namaKawasan,
  518. "nama_taman" => $request->namaTaman,
  519. "nama_jalan" => $request->namaJalan,
  520. "no_parking" => $request->noParking,
  521. "catatan" => $request->catatan,
  522. "lokasi_kejadian" => '-',
  523. 'latlong' => $request->Latlong,
  524. 'jbkod' => $request->jabatan,
  525. 'akta' => $faulty->deed_law_id,
  526. 'seksyen_kesalahan' => $faulty->_id,
  527. 'jumlah_asal_kompaun' => $faulty->amount,
  528. 'jumlah_kemaskini_kompaun' => '',
  529. 'dikeluarkan' => $staff->_id,
  530. "status" => 'Belum Bayar',
  531. "amount_payment" => '',
  532. "receipt" => '',
  533. "modul" => $request->modul,
  534. "penguatkuasa" => '',
  535. ];
  536. }elseif($request->jenis == 'Pelbagai_KT'){
  537. $compoundData = [
  538. 'jenis' => $request->jenis,
  539. 'kpd' => $kpd,
  540. 'nama' => $request->namaP,
  541. 'identity' => $request->noIc,
  542. 'nama_syarikat' => $request->namaS,
  543. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  544. 'alamat' => $request->alamat,
  545. "no_plate" => $request->no_plate,
  546. "no_cukai_jalan" => $request->no_cukai_jalan,
  547. "nama_kawasan" => $request->namaKawasan,
  548. "nama_taman" => $request->namaTaman,
  549. "nama_jalan" => $request->namaJalan,
  550. "catatan" => $request->catatan,
  551. "lokasi_kejadian" => '-',
  552. 'latlong' => $request->Latlong,
  553. 'jbkod' => $request->jabatan,
  554. 'akta' => $faulty->deed_law_id,
  555. 'seksyen_kesalahan' => $faulty->_id,
  556. 'jumlah_asal_kompaun' => $faulty->amount,
  557. 'jumlah_kemaskini_kompaun' => '',
  558. 'dikeluarkan' => $staff->_id,
  559. "status" => 'Belum Bayar',
  560. "amount_payment" => '',
  561. "receipt" => '',
  562. "modul" => $request->modul,
  563. "penguatkuasa" => '',
  564. "no_telefon" => $request->tel,
  565. "no_akaun_lesen" => $request->lesen,
  566. "maklumat_tambahan" => '-',
  567. "tindakan" => $request->tindakan,
  568. "tempoh" => $request->tempoh,
  569. ];
  570. }elseif($request->jenis == 'Pelbagai_JPB'){
  571. $compoundData = [
  572. 'jenis' => $request->jenis,
  573. 'kpd' => $kpd,
  574. 'nama' => $request->namaP,
  575. 'identity' => $request->noIc,
  576. 'nama_syarikat' => $request->namaS,
  577. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  578. 'alamat' => $request->alamat,
  579. "no_plate" => $request->no_plate,
  580. "no_cukai_jalan" => $request->no_cukai_jalan,
  581. "nama_kawasan" => $request->namaKawasan,
  582. "nama_taman" => $request->namaTaman,
  583. "nama_jalan" => $request->namaJalan,
  584. "catatan" => $request->catatan,
  585. "lokasi_kejadian" => '-',
  586. 'latlong' => $request->Latlong,
  587. 'jbkod' => $request->jabatan,
  588. 'akta' => $faulty->deed_law_id,
  589. 'seksyen_kesalahan' => $faulty->_id,
  590. 'jumlah_asal_kompaun' => $faulty->amount,
  591. 'jumlah_kemaskini_kompaun' => '',
  592. 'dikeluarkan' => $staff->_id,
  593. "status" => 'Belum Bayar',
  594. "amount_payment" => '',
  595. "receipt" => '',
  596. "modul" => $request->modul,
  597. "penguatkuasa" => '',
  598. "no_telefon" => $request->tel,
  599. "no_akaun_lesen" => $request->lesen,
  600. "maklumat_tambahan" => '-',
  601. "tindakan" => $request->tindakan,
  602. "tempoh" => $request->tempoh,
  603. ];
  604. }
  605. elseif($request->jenis == 'Pelbagai_LESEN'){
  606. $compoundData = [
  607. 'jenis' => $request->jenis,
  608. 'kpd' => $kpd,
  609. 'nama' => $request->namaP,
  610. 'identity' => $request->noIc,
  611. 'nama_syarikat' => $request->namaS,
  612. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  613. 'alamat' => $request->alamat,
  614. "no_plate" => $request->no_plate,
  615. "no_cukai_jalan" => $request->no_cukai_jalan,
  616. "nama_kawasan" => $request->namaKawasan,
  617. "nama_taman" => $request->namaTaman,
  618. "nama_jalan" => $request->namaJalan,
  619. "catatan" => $request->catatan,
  620. "lokasi_kejadian" => '-',
  621. 'latlong' => $request->Latlong,
  622. 'jbkod' => $request->jabatan,
  623. 'akta' => $faulty->deed_law_id,
  624. 'seksyen_kesalahan' => $faulty->_id,
  625. 'jumlah_asal_kompaun' => $faulty->amount,
  626. 'jumlah_kemaskini_kompaun' => '',
  627. 'dikeluarkan' => $staff->_id,
  628. "status" => 'Belum Bayar',
  629. "amount_payment" => '',
  630. "receipt" => '',
  631. "modul" => $request->modul,
  632. "penguatkuasa" => '',
  633. "no_telefon" => $request->tel,
  634. "no_akaun_lesen" => $request->lesen,
  635. "maklumat_tambahan" => '-',
  636. ];
  637. }
  638. elseif($request->jenis == 'Pelbagai_PA'){
  639. $compoundData = [
  640. 'jenis' => $request->jenis,
  641. 'kpd' => $kpd,
  642. 'nama' => $request->namaP,
  643. 'identity' => $request->noIc,
  644. 'nama_syarikat' => $request->namaS,
  645. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  646. 'alamat' => $request->alamat,
  647. "no_plate" => $request->no_plate,
  648. "no_cukai_jalan" => $request->no_cukai_jalan,
  649. "nama_kawasan" => $request->namaKawasan,
  650. "nama_taman" => $request->namaTaman,
  651. "nama_jalan" => $request->namaJalan,
  652. "catatan" => $request->catatan,
  653. "lokasi_kejadian" => '-',
  654. 'latlong' => $request->Latlong,
  655. 'jbkod' => $request->jabatan,
  656. 'akta' => $faulty->deed_law_id,
  657. 'seksyen_kesalahan' => $faulty->_id,
  658. 'jumlah_asal_kompaun' => $faulty->amount,
  659. 'jumlah_kemaskini_kompaun' => '',
  660. 'dikeluarkan' => $staff->_id,
  661. "status" => 'Belum Bayar',
  662. "amount_payment" => '',
  663. "receipt" => '',
  664. "modul" => $request->modul,
  665. "penguatkuasa" => '',
  666. "no_telefon" => $request->tel,
  667. "no_akaun_lesen" => $request->lesen,
  668. "maklumat_tambahan" => '-',
  669. "bil_haiwan" => $request->bil_haiwan,
  670. ];
  671. }
  672. $file = ConfidentialFile::create($fileData);
  673. $saved = $file->compound()->create($compoundData);
  674. if($saved){
  675. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  676. // if(!empty($compound)){
  677. dispatch(new UpdateCompoundPrice($kpd));
  678. // $tawaran = '';
  679. // if($compound->jumlah_kemaskini_kompaun != ''){
  680. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  681. // }else{
  682. // $tawaran = $compound->jumlah_asal_kompaun;
  683. // }
  684. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  685. array_push($data, array('kpd' => $kpd));
  686. // $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  687. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  688. // }
  689. }
  690. }
  691. }
  692. }
  693. /**
  694. * Display the specified resource.
  695. *
  696. * @param int $id
  697. * @return \Illuminate\Http\Response
  698. */
  699. public function show($id)
  700. {
  701. //
  702. }
  703. /**
  704. * Show the form for editing the specified resource.
  705. *
  706. * @param int $id
  707. * @return \Illuminate\Http\Response
  708. */
  709. public function edit($id)
  710. {
  711. //
  712. }
  713. /**
  714. * Update the specified resource in storage.
  715. *
  716. * @param \Illuminate\Http\Request $request
  717. * @param int $id
  718. * @return \Illuminate\Http\Response
  719. */
  720. public function update(Request $request, $id)
  721. {
  722. //
  723. }
  724. public function updateStatusPaymentViaDashboard(Request $request)
  725. {
  726. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  727. $staff = StaffDetail::find($request->current_id);
  728. if(!empty($compound) && !empty($staff)){
  729. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  730. if($compound->status != $request->status){
  731. $compound->status = $request->status;
  732. $compound->catatan_dari_admin = $request->remark;
  733. $compound->amount_payment = $request->amount;
  734. $compound->update_by = $request->current_id;
  735. $saved = $compound->save();
  736. if($saved){
  737. $gDate = $compound->created_at->format('F Y');
  738. $historyData = [
  739. 'tarikh_kumpulan' => $gDate,
  740. ];
  741. $subHistory = [
  742. 'no_siri' => $compound->ConfidentialFile->no_siri,
  743. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  744. 'huraian' => "Status pembayaran kompaun (RM ".$request->amount.") telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  745. ];
  746. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  747. if(!empty($groupByDate)){
  748. $groupByDate->subhistory()->create($subHistory);
  749. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  750. }else{
  751. $history = History::create($historyData);
  752. $history->subhistory()->create($subHistory);
  753. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  754. }
  755. if($request->status == "Berbayar"){
  756. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  757. }else{
  758. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  759. }
  760. }else{
  761. $response = [
  762. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  763. ];
  764. return response()->json($response, 200);
  765. }
  766. }else{
  767. if($request->remark != ''){
  768. $compound->catatan_dari_admin = $request->remark;
  769. $compound->update_by = $request->current_id;
  770. $compound->save();
  771. $saved = $compound->save();
  772. if($saved){
  773. $gDate = $compound->created_at->format('F Y');
  774. $historyData = [
  775. 'tarikh_kumpulan' => $gDate,
  776. ];
  777. $subHistory = [
  778. 'no_siri' => $compound->ConfidentialFile->no_siri,
  779. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  780. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  781. ];
  782. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  783. if(!empty($groupByDate)){
  784. $groupByDate->subhistory()->create($subHistory);
  785. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  786. }else{
  787. $history = History::create($historyData);
  788. $history->subhistory()->create($subHistory);
  789. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  790. }
  791. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  792. }else{
  793. $response = [
  794. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  795. ];
  796. return response()->json($response, 200);
  797. }
  798. }else{
  799. $response = [
  800. 'success' => false, 'message' => 'Tiada kemaskini!',
  801. ];
  802. return response()->json($response, 200);
  803. }
  804. }
  805. }else{
  806. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  807. $compound->status = $request->status;
  808. $compound->catatan_dari_admin = $request->remark;
  809. $compound->amount_payment = $request->amount;
  810. $compound->update_by = $request->current_id;
  811. $saved = $compound->save();
  812. if($saved){
  813. $gDate = $compound->created_at->format('F Y');
  814. $historyData = [
  815. 'tarikh_kumpulan' => $gDate,
  816. ];
  817. $subHistory = [
  818. 'no_siri' => $compound->ConfidentialFile->no_siri,
  819. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  820. 'huraian' => "Status pembayaran kompaun (RM ".$request->amount.") telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  821. ];
  822. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  823. if(!empty($groupByDate)){
  824. $groupByDate->subhistory()->create($subHistory);
  825. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  826. }else{
  827. $history = History::create($historyData);
  828. $history->subhistory()->create($subHistory);
  829. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  830. }
  831. if($request->status == "Berbayar"){
  832. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  833. }else{
  834. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  835. }
  836. }else{
  837. $response = [
  838. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  839. ];
  840. return response()->json($response, 200);
  841. }
  842. }else{
  843. if($request->remark != ''){
  844. $compound->catatan_dari_admin = $request->remark;
  845. $compound->update_by = $request->current_id;
  846. $compound->save();
  847. $saved = $compound->save();
  848. if($saved){
  849. $gDate = $compound->created_at->format('F Y');
  850. $historyData = [
  851. 'tarikh_kumpulan' => $gDate,
  852. ];
  853. $subHistory = [
  854. 'no_siri' => $compound->ConfidentialFile->no_siri,
  855. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  856. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  857. ];
  858. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  859. if(!empty($groupByDate)){
  860. $groupByDate->subhistory()->create($subHistory);
  861. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  862. }else{
  863. $history = History::create($historyData);
  864. $history->subhistory()->create($subHistory);
  865. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  866. }
  867. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  868. }else{
  869. $response = [
  870. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  871. ];
  872. return response()->json($response, 200);
  873. }
  874. }else{
  875. $response = [
  876. 'success' => false, 'message' => 'Tiada kemaskini!',
  877. ];
  878. return response()->json($response, 200);
  879. }
  880. }
  881. }
  882. }else{
  883. $response = [
  884. 'success' => false,
  885. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  886. ];
  887. return response()->json($response, 200);
  888. }
  889. }
  890. /**
  891. * Remove the specified resource from storage.
  892. *
  893. * @param int $id
  894. * @return \Illuminate\Http\Response
  895. */
  896. public function destroy($id)
  897. {
  898. //
  899. }
  900. }