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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  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. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  687. // }
  688. }
  689. }
  690. }
  691. }
  692. /**
  693. * Display the specified resource.
  694. *
  695. * @param int $id
  696. * @return \Illuminate\Http\Response
  697. */
  698. public function show($id)
  699. {
  700. //
  701. }
  702. /**
  703. * Show the form for editing the specified resource.
  704. *
  705. * @param int $id
  706. * @return \Illuminate\Http\Response
  707. */
  708. public function edit($id)
  709. {
  710. //
  711. }
  712. /**
  713. * Update the specified resource in storage.
  714. *
  715. * @param \Illuminate\Http\Request $request
  716. * @param int $id
  717. * @return \Illuminate\Http\Response
  718. */
  719. public function update(Request $request, $id)
  720. {
  721. //
  722. }
  723. public function updateStatusPaymentViaDashboard(Request $request)
  724. {
  725. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  726. $staff = StaffDetail::find($request->current_id);
  727. if(!empty($compound) && !empty($staff)){
  728. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  729. if($compound->status != $request->status){
  730. $compound->status = $request->status;
  731. $compound->catatan_dari_admin = $request->remark;
  732. $compound->amount_payment = $request->amount;
  733. $compound->update_by = $request->current_id;
  734. $saved = $compound->save();
  735. if($saved){
  736. $gDate = $compound->created_at->format('F Y');
  737. $historyData = [
  738. 'tarikh_kumpulan' => $gDate,
  739. ];
  740. $subHistory = [
  741. 'no_siri' => $compound->ConfidentialFile->no_siri,
  742. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  743. '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>",
  744. ];
  745. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  746. if(!empty($groupByDate)){
  747. $groupByDate->subhistory()->create($subHistory);
  748. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  749. }else{
  750. $history = History::create($historyData);
  751. $history->subhistory()->create($subHistory);
  752. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  753. }
  754. if($request->status == "Berbayar"){
  755. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  756. }else{
  757. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  758. }
  759. }else{
  760. $response = [
  761. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  762. ];
  763. return response()->json($response, 200);
  764. }
  765. }else{
  766. if($request->remark != ''){
  767. $compound->catatan_dari_admin = $request->remark;
  768. $compound->update_by = $request->current_id;
  769. $compound->save();
  770. $saved = $compound->save();
  771. if($saved){
  772. $gDate = $compound->created_at->format('F Y');
  773. $historyData = [
  774. 'tarikh_kumpulan' => $gDate,
  775. ];
  776. $subHistory = [
  777. 'no_siri' => $compound->ConfidentialFile->no_siri,
  778. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  779. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  780. ];
  781. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  782. if(!empty($groupByDate)){
  783. $groupByDate->subhistory()->create($subHistory);
  784. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  785. }else{
  786. $history = History::create($historyData);
  787. $history->subhistory()->create($subHistory);
  788. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  789. }
  790. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  791. }else{
  792. $response = [
  793. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  794. ];
  795. return response()->json($response, 200);
  796. }
  797. }else{
  798. $response = [
  799. 'success' => false, 'message' => 'Tiada kemaskini!',
  800. ];
  801. return response()->json($response, 200);
  802. }
  803. }
  804. }else{
  805. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  806. $compound->status = $request->status;
  807. $compound->catatan_dari_admin = $request->remark;
  808. $compound->amount_payment = $request->amount;
  809. $compound->update_by = $request->current_id;
  810. $saved = $compound->save();
  811. if($saved){
  812. $gDate = $compound->created_at->format('F Y');
  813. $historyData = [
  814. 'tarikh_kumpulan' => $gDate,
  815. ];
  816. $subHistory = [
  817. 'no_siri' => $compound->ConfidentialFile->no_siri,
  818. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  819. '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>",
  820. ];
  821. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  822. if(!empty($groupByDate)){
  823. $groupByDate->subhistory()->create($subHistory);
  824. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  825. }else{
  826. $history = History::create($historyData);
  827. $history->subhistory()->create($subHistory);
  828. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  829. }
  830. if($request->status == "Berbayar"){
  831. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  832. }else{
  833. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  834. }
  835. }else{
  836. $response = [
  837. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  838. ];
  839. return response()->json($response, 200);
  840. }
  841. }else{
  842. if($request->remark != ''){
  843. $compound->catatan_dari_admin = $request->remark;
  844. $compound->update_by = $request->current_id;
  845. $compound->save();
  846. $saved = $compound->save();
  847. if($saved){
  848. $gDate = $compound->created_at->format('F Y');
  849. $historyData = [
  850. 'tarikh_kumpulan' => $gDate,
  851. ];
  852. $subHistory = [
  853. 'no_siri' => $compound->ConfidentialFile->no_siri,
  854. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  855. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  856. ];
  857. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  858. if(!empty($groupByDate)){
  859. $groupByDate->subhistory()->create($subHistory);
  860. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  861. }else{
  862. $history = History::create($historyData);
  863. $history->subhistory()->create($subHistory);
  864. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  865. }
  866. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  867. }else{
  868. $response = [
  869. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  870. ];
  871. return response()->json($response, 200);
  872. }
  873. }else{
  874. $response = [
  875. 'success' => false, 'message' => 'Tiada kemaskini!',
  876. ];
  877. return response()->json($response, 200);
  878. }
  879. }
  880. }
  881. }else{
  882. $response = [
  883. 'success' => false,
  884. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  885. ];
  886. return response()->json($response, 200);
  887. }
  888. }
  889. /**
  890. * Remove the specified resource from storage.
  891. *
  892. * @param int $id
  893. * @return \Illuminate\Http\Response
  894. */
  895. public function destroy($id)
  896. {
  897. //
  898. }
  899. }