Dashboard sipadu mbip
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CompoundResourceController.php 46KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  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. $saved ='';
  294. $kpd = '';
  295. $no_siri = '';
  296. $data = array();
  297. if($request->jenis == 'Parkir')
  298. {
  299. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  300. if(!empty($faulty)){
  301. $countKPD = $this->compound->withTrashed()->count();
  302. do {
  303. $countKPD = $countKPD + 1;
  304. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  305. $kpd = 'KP' . $countKPD;
  306. $no_siri = date('yn').'-'.$countKPD;
  307. $fileData = [
  308. 'no_siri' => $no_siri,
  309. ];
  310. //only for compound parkir
  311. $compoundData = [
  312. 'jenis' => 'Parkir',
  313. 'kpd' => $kpd,
  314. 'nama' => '-',
  315. 'identity' => '-',
  316. 'alamat' => '-',
  317. "no_plate" => strtolower($request->no_plate),
  318. "no_cukai_jalan" => $request->noCukaijalan,
  319. "jenis_kenderaan" => $request->jenisKenderaan,
  320. "model_kenderaan" => $request->modelKenderaan,
  321. "warna_kenderaan" => $request->warnakenderaan,
  322. "nama_kawasan" => $request->namaKawasan,
  323. "nama_taman" => $request->namaTaman,
  324. "nama_jalan" => $request->namaJalan,
  325. "no_parking" => $request->noParking,
  326. "catatan" => $request->catatan,
  327. "lokasi_kejadian" => '-',
  328. 'latlong' => $request->Latlong,
  329. 'jbkod' => $request->jabatan,
  330. 'akta' => $faulty->deed_law_id,
  331. 'seksyen_kesalahan' => $faulty->_id,
  332. 'jumlah_asal_kompaun' => $faulty->amount,
  333. 'jumlah_kemaskini_kompaun' => '',
  334. 'dikeluarkan' => $staff->_id,
  335. "status" => 'Belum Bayar',
  336. "amount_payment" => '',
  337. "receipt" => '',
  338. "modul" => '03',
  339. "penguatkuasa" => '',
  340. "cpn_created" => Carbon::now()->toDateTimeString(),
  341. ];
  342. $file = ConfidentialFile::create($fileData);
  343. $saved = $file->compound()->create($compoundData);
  344. }
  345. }elseif(($request->jenis == 'Pelbagai_KT') || ($request->jenis == 'Pelbagai_JPB') || ($request->jenis == 'Pelbagai_PA') ||
  346. ($request->jenis == 'Pelbagai_LESEN')){
  347. $kpd = $request->kpd;
  348. // $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  349. // $fileData = [
  350. // 'no_siri' => $no_siri,
  351. // ];
  352. // $file = ConfidentialFile::create($fileData);
  353. $compound = Compound::where('jenis', $request->jenis)->where('kpd', $kpd)->first();
  354. if (!empty($compound)) {
  355. if(!($compound->modul == '03'))
  356. {
  357. if($request->jenis == 'Pelbagai_KT'){
  358. $compound->jenis = $request->jenis;
  359. $compound->nama = $request->namaP;
  360. $compound->identity = $request->noIc;
  361. $compound->nama_syarikat = $request->namaS;
  362. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  363. $compound->alamat = $request->alamat;
  364. $compound->no_plate = $request->no_plate;
  365. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  366. // $compound->nama_kawasan = $request->namaKawasan;
  367. // $compound->nama_taman = $request->namaTaman;
  368. // $compound->nama_jalan = $request->namaJalan;
  369. $compound->catatan = $request->catatan;
  370. $compound->latlong = $request->Latlong;
  371. // $compound->akta = $faulty->deed_law_id;
  372. // $compound->seksyen_kesalahan = $faulty->_id;
  373. // $compound->jumlah_asal_kompaun = $faulty->amount;
  374. $compound->dikeluarkan_ = $staff->_id;
  375. $compound->status = 'Belum Bayar';
  376. $compound->modul = '03';
  377. $compound->no_telefon = $request->tel;
  378. $compound->no_akaun_lesen = $request->lesen;
  379. $compound->cpn_created = Carbon::now()->toDateTimeString();
  380. }elseif($request->jenis == 'Pelbagai_JPB'){
  381. $compound->jenis = $request->jenis;
  382. $compound->nama = $request->namaP;
  383. $compound->identity = $request->noIc;
  384. $compound->nama_syarikat = $request->namaS;
  385. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  386. $compound->alamat = $request->alamat;
  387. $compound->no_plate = $request->no_plate;
  388. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  389. // $compound->nama_kawasan => $request->namaKawasan;
  390. // $compound->nama_taman => $request->namaTaman;
  391. // $compound->nama_jalan => $request->namaJalan;
  392. $compound->catatan = $request->catatan;
  393. $compound->latlong = $request->Latlong;
  394. // $compound->akta => $faulty->deed_law_id;
  395. // $compound->seksyen_kesalahan => $faulty->_id;
  396. // $compound->jumlah_asal_kompaun => $faulty->amount;
  397. $compound->dikeluarkan_ = $staff->_id;
  398. $compound->status = 'Belum Bayar';
  399. $compound->modul = '03';
  400. $compound->no_telefon = $request->tel;
  401. $compound->no_akaun_lesen = $request->lesen;
  402. $compound->cpn_created = Carbon::now()->toDateTimeString();
  403. }elseif($request->jenis == 'Pelbagai_PA'){
  404. $compound->jenis = $request->jenis;
  405. $compound->nama = $request->namaP;
  406. $compound->identity = $request->noIc;
  407. $compound->nama_syarikat = $request->namaS;
  408. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  409. $compound->alamat = $request->alamat;
  410. $compound->no_plate = $request->no_plate;
  411. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  412. // $compound->nama_kawasan = $request->namaKawasan;
  413. // $compound->nama_taman = $request->namaTaman;
  414. // $compound->nama_jalan = $request->namaJalan;
  415. $compound->catatan = $request->catatan;
  416. $compound->latlong = $request->Latlong;
  417. // $compound->akta = $faulty->deed_law_id;
  418. // $compound->seksyen_kesalahan = $faulty->_id;
  419. // $compound->jumlah_asal_kompaun = $faulty->amount;
  420. $compound->dikeluarkan_ = $staff->_id;
  421. $compound->status = 'Belum Bayar';
  422. $compound->modul = '03';
  423. $compound->no_telefon = $request->tel;
  424. $compound->no_akaun_lesen = $request->lesen;
  425. $compound->bil_haiwan = $request->lesen;
  426. $compound->cpn_created = Carbon::now()->toDateTimeString();
  427. }elseif($request->jenis == 'Pelbagai_LESEN'){
  428. $compound->jenis = $request->jenis;
  429. $compound->nama = $request->namaP;
  430. $compound->identity = $request->noIc;
  431. $compound->nama_syarikat = $request->namaS;
  432. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  433. $compound->alamat = $request->alamat;
  434. $compound->no_plate = $request->no_plate;
  435. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  436. // $compound->nama_kawasan = $request->namaKawasan;
  437. // $compound->nama_taman = $request->namaTaman;
  438. // $compound->nama_jalan = $request->namaJalan;
  439. $compound->catatan = $request->catatan;
  440. $compound->latlong = $request->Latlong;
  441. // $compound->akta = $faulty->deed_law_id;
  442. // $compound->seksyen_kesalahan = $faulty->_id;
  443. // $compound->jumlah_asal_kompaun = $faulty->amount;
  444. $compound->dikeluarkan_ = $staff->_id;
  445. $compound->status = 'Belum Bayar';
  446. $compound->modul = '03';
  447. $compound->no_telefon = $request->tel;
  448. $compound->no_akaun_lesen = $request->lesen;
  449. $compound->cpn_created = Carbon::now()->toDateTimeString();
  450. }
  451. $saved = $compound->save();
  452. }
  453. else
  454. {
  455. return $this->sendResponse('', 'Kompaun ini telah dikeluarkan!');
  456. }
  457. }
  458. }
  459. if($saved){
  460. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  461. // if(!empty($compound)){
  462. dispatch(new UpdateCompoundPrice($kpd));
  463. // $tawaran = '';
  464. // if($compound->jumlah_kemaskini_kompaun != ''){
  465. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  466. // }else{
  467. // $tawaran = $compound->jumlah_asal_kompaun;
  468. // }
  469. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  470. array_push($data, array('kpd' => $kpd));
  471. // $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  472. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  473. // }
  474. }
  475. }
  476. }
  477. public function storeNotice(Request $request)
  478. {
  479. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  480. if(empty($staff)){
  481. return $this->sendError('Invalid', 'Staff not existed');
  482. }else {
  483. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  484. if(!empty($faulty)){
  485. $data = array();
  486. $countKPD = $this->compound->withTrashed()->count();
  487. do {
  488. $countKPD = $countKPD + 1;
  489. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  490. $kpd = 'KP' . $countKPD;
  491. $no_siri = date('yn').'-'.$countKPD;
  492. $fileData = [
  493. 'no_siri' => $no_siri,
  494. ];
  495. if($request->jenis == 'Parkir'){
  496. $compoundData = [
  497. 'jenis' => 'Parkir',
  498. 'kpd' => $kpd,
  499. 'nama' => '-',
  500. 'identity' => '-',
  501. 'alamat' => '-',
  502. "no_plate" => strtolower($request->no_plate),
  503. "no_cukai_jalan" => $request->noCukaijalan,
  504. "jenis_kenderaan" => $request->jenisKenderaan,
  505. "model_kenderaan" => $request->modelKenderaan,
  506. "warna_kenderaan" => $request->warnakenderaan,
  507. "nama_kawasan" => $request->namaKawasan,
  508. "nama_taman" => $request->namaTaman,
  509. "nama_jalan" => $request->namaJalan,
  510. "no_parking" => $request->noParking,
  511. "catatan" => $request->catatan,
  512. "lokasi_kejadian" => '-',
  513. 'latlong' => $request->Latlong,
  514. 'jbkod' => $request->jabatan,
  515. 'akta' => $faulty->deed_law_id,
  516. 'seksyen_kesalahan' => $faulty->_id,
  517. 'jumlah_asal_kompaun' => $faulty->amount,
  518. 'jumlah_kemaskini_kompaun' => '',
  519. 'dikeluarkan' => $staff->_id,
  520. "status" => 'Belum Bayar',
  521. "amount_payment" => '',
  522. "receipt" => '',
  523. "modul" => $request->modul,
  524. "penguatkuasa" => '',
  525. "notis_created" => Carbon::now()->toDateTimeString(),
  526. ];
  527. }elseif($request->jenis == 'Pelbagai_KT'){
  528. $compoundData = [
  529. 'jenis' => $request->jenis,
  530. 'kpd' => $kpd,
  531. 'nama' => $request->namaP,
  532. 'identity' => $request->noIc,
  533. 'nama_syarikat' => $request->namaS,
  534. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  535. 'alamat' => $request->alamat,
  536. "no_plate" => $request->no_plate,
  537. "no_cukai_jalan" => $request->no_cukai_jalan,
  538. "nama_kawasan" => $request->namaKawasan,
  539. "nama_taman" => $request->namaTaman,
  540. "nama_jalan" => $request->namaJalan,
  541. "catatan" => $request->catatan,
  542. "lokasi_kejadian" => '-',
  543. 'latlong' => $request->Latlong,
  544. 'jbkod' => $request->jabatan,
  545. 'akta' => $faulty->deed_law_id,
  546. 'seksyen_kesalahan' => $faulty->_id,
  547. 'jumlah_asal_kompaun' => $faulty->amount,
  548. 'jumlah_kemaskini_kompaun' => '',
  549. 'dikeluarkan' => $staff->_id,
  550. "status" => 'Belum Bayar',
  551. "amount_payment" => '',
  552. "receipt" => '',
  553. "modul" => $request->modul,
  554. "penguatkuasa" => '',
  555. "no_telefon" => $request->tel,
  556. "no_akaun_lesen" => $request->lesen,
  557. "maklumat_tambahan" => '-',
  558. "tindakan" => $request->tindakan,
  559. "tempoh" => $request->tempoh,
  560. "notis_created" => Carbon::now()->toDateTimeString(),
  561. ];
  562. }elseif($request->jenis == 'Pelbagai_JPB'){
  563. $compoundData = [
  564. 'jenis' => $request->jenis,
  565. 'kpd' => $kpd,
  566. 'nama' => $request->namaP,
  567. 'identity' => $request->noIc,
  568. 'nama_syarikat' => $request->namaS,
  569. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  570. 'alamat' => $request->alamat,
  571. "no_plate" => $request->no_plate,
  572. "no_cukai_jalan" => $request->no_cukai_jalan,
  573. "nama_kawasan" => $request->namaKawasan,
  574. "nama_taman" => $request->namaTaman,
  575. "nama_jalan" => $request->namaJalan,
  576. "catatan" => $request->catatan,
  577. "lokasi_kejadian" => '-',
  578. 'latlong' => $request->Latlong,
  579. 'jbkod' => $request->jabatan,
  580. 'akta' => $faulty->deed_law_id,
  581. 'seksyen_kesalahan' => $faulty->_id,
  582. 'jumlah_asal_kompaun' => $faulty->amount,
  583. 'jumlah_kemaskini_kompaun' => '',
  584. 'dikeluarkan' => $staff->_id,
  585. "status" => 'Belum Bayar',
  586. "amount_payment" => '',
  587. "receipt" => '',
  588. "modul" => $request->modul,
  589. "penguatkuasa" => '',
  590. "no_telefon" => $request->tel,
  591. "no_akaun_lesen" => $request->lesen,
  592. "maklumat_tambahan" => '-',
  593. "tindakan" => $request->tindakan,
  594. "tempoh" => $request->tempoh,
  595. "notis_created" => Carbon::now()->toDateTimeString(),
  596. ];
  597. }
  598. elseif($request->jenis == 'Pelbagai_LESEN'){
  599. $compoundData = [
  600. 'jenis' => $request->jenis,
  601. 'kpd' => $kpd,
  602. 'nama' => $request->namaP,
  603. 'identity' => $request->noIc,
  604. 'nama_syarikat' => $request->namaS,
  605. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  606. 'alamat' => $request->alamat,
  607. "no_plate" => $request->no_plate,
  608. "no_cukai_jalan" => $request->no_cukai_jalan,
  609. "nama_kawasan" => $request->namaKawasan,
  610. "nama_taman" => $request->namaTaman,
  611. "nama_jalan" => $request->namaJalan,
  612. "catatan" => $request->catatan,
  613. "lokasi_kejadian" => '-',
  614. 'latlong' => $request->Latlong,
  615. 'jbkod' => $request->jabatan,
  616. 'akta' => $faulty->deed_law_id,
  617. 'seksyen_kesalahan' => $faulty->_id,
  618. 'jumlah_asal_kompaun' => $faulty->amount,
  619. 'jumlah_kemaskini_kompaun' => '',
  620. 'dikeluarkan' => $staff->_id,
  621. "status" => 'Belum Bayar',
  622. "amount_payment" => '',
  623. "receipt" => '',
  624. "modul" => $request->modul,
  625. "penguatkuasa" => '',
  626. "no_telefon" => $request->tel,
  627. "no_akaun_lesen" => $request->lesen,
  628. "maklumat_tambahan" => '-',
  629. "notis_created" => Carbon::now()->toDateTimeString(),
  630. ];
  631. }
  632. elseif($request->jenis == 'Pelbagai_PA'){
  633. $compoundData = [
  634. 'jenis' => $request->jenis,
  635. 'kpd' => $kpd,
  636. 'nama' => $request->namaP,
  637. 'identity' => $request->noIc,
  638. 'nama_syarikat' => $request->namaS,
  639. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  640. 'alamat' => $request->alamat,
  641. "no_plate" => $request->no_plate,
  642. "no_cukai_jalan" => $request->no_cukai_jalan,
  643. "nama_kawasan" => $request->namaKawasan,
  644. "nama_taman" => $request->namaTaman,
  645. "nama_jalan" => $request->namaJalan,
  646. "catatan" => $request->catatan,
  647. "lokasi_kejadian" => '-',
  648. 'latlong' => $request->Latlong,
  649. 'jbkod' => $request->jabatan,
  650. 'akta' => $faulty->deed_law_id,
  651. 'seksyen_kesalahan' => $faulty->_id,
  652. 'jumlah_asal_kompaun' => $faulty->amount,
  653. 'jumlah_kemaskini_kompaun' => '',
  654. 'dikeluarkan' => $staff->_id,
  655. "status" => 'Belum Bayar',
  656. "amount_payment" => '',
  657. "receipt" => '',
  658. "modul" => $request->modul,
  659. "penguatkuasa" => '',
  660. "no_telefon" => $request->tel,
  661. "no_akaun_lesen" => $request->lesen,
  662. "maklumat_tambahan" => '-',
  663. "bil_haiwan" => $request->bil_haiwan,
  664. "notis_created" => Carbon::now()->toDateTimeString(),
  665. ];
  666. }
  667. $file = ConfidentialFile::create($fileData);
  668. $saved = $file->compound()->create($compoundData);
  669. if($saved){
  670. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  671. // if(!empty($compound)){
  672. dispatch(new UpdateCompoundPrice($kpd));
  673. // $tawaran = '';
  674. // if($compound->jumlah_kemaskini_kompaun != ''){
  675. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  676. // }else{
  677. // $tawaran = $compound->jumlah_asal_kompaun;
  678. // }
  679. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  680. array_push($data, array('kpd' => $kpd));
  681. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  682. // }
  683. }
  684. }
  685. }
  686. }
  687. /**
  688. * Display the specified resource.
  689. *
  690. * @param int $id
  691. * @return \Illuminate\Http\Response
  692. */
  693. public function show($id)
  694. {
  695. //
  696. }
  697. /**
  698. * Show the form for editing the specified resource.
  699. *
  700. * @param int $id
  701. * @return \Illuminate\Http\Response
  702. */
  703. public function edit($id)
  704. {
  705. //
  706. }
  707. /**
  708. * Update the specified resource in storage.
  709. *
  710. * @param \Illuminate\Http\Request $request
  711. * @param int $id
  712. * @return \Illuminate\Http\Response
  713. */
  714. public function update(Request $request, $id)
  715. {
  716. //
  717. }
  718. public function updateStatusPaymentViaDashboard(Request $request)
  719. {
  720. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  721. $staff = StaffDetail::find($request->current_id);
  722. if(!empty($compound) && !empty($staff)){
  723. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  724. if($compound->status != $request->status){
  725. $compound->status = $request->status;
  726. $compound->catatan_dari_admin = $request->remark;
  727. $compound->amount_payment = $request->amount;
  728. $compound->update_by = $request->current_id;
  729. $saved = $compound->save();
  730. if($saved){
  731. $gDate = $compound->created_at->format('F Y');
  732. $historyData = [
  733. 'tarikh_kumpulan' => $gDate,
  734. ];
  735. $subHistory = [
  736. 'no_siri' => $compound->ConfidentialFile->no_siri,
  737. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  738. '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>",
  739. ];
  740. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  741. if(!empty($groupByDate)){
  742. $groupByDate->subhistory()->create($subHistory);
  743. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  744. }else{
  745. $history = History::create($historyData);
  746. $history->subhistory()->create($subHistory);
  747. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  748. }
  749. if($request->status == "Berbayar"){
  750. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  751. }else{
  752. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  753. }
  754. }else{
  755. $response = [
  756. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  757. ];
  758. return response()->json($response, 200);
  759. }
  760. }else{
  761. if($request->remark != ''){
  762. $compound->catatan_dari_admin = $request->remark;
  763. $compound->update_by = $request->current_id;
  764. $compound->save();
  765. $saved = $compound->save();
  766. if($saved){
  767. $gDate = $compound->created_at->format('F Y');
  768. $historyData = [
  769. 'tarikh_kumpulan' => $gDate,
  770. ];
  771. $subHistory = [
  772. 'no_siri' => $compound->ConfidentialFile->no_siri,
  773. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  774. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  775. ];
  776. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  777. if(!empty($groupByDate)){
  778. $groupByDate->subhistory()->create($subHistory);
  779. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  780. }else{
  781. $history = History::create($historyData);
  782. $history->subhistory()->create($subHistory);
  783. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  784. }
  785. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  786. }else{
  787. $response = [
  788. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  789. ];
  790. return response()->json($response, 200);
  791. }
  792. }else{
  793. $response = [
  794. 'success' => false, 'message' => 'Tiada kemaskini!',
  795. ];
  796. return response()->json($response, 200);
  797. }
  798. }
  799. }else{
  800. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  801. $compound->status = $request->status;
  802. $compound->catatan_dari_admin = $request->remark;
  803. $compound->amount_payment = $request->amount;
  804. $compound->update_by = $request->current_id;
  805. $saved = $compound->save();
  806. if($saved){
  807. $gDate = $compound->created_at->format('F Y');
  808. $historyData = [
  809. 'tarikh_kumpulan' => $gDate,
  810. ];
  811. $subHistory = [
  812. 'no_siri' => $compound->ConfidentialFile->no_siri,
  813. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  814. '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>",
  815. ];
  816. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  817. if(!empty($groupByDate)){
  818. $groupByDate->subhistory()->create($subHistory);
  819. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  820. }else{
  821. $history = History::create($historyData);
  822. $history->subhistory()->create($subHistory);
  823. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  824. }
  825. if($request->status == "Berbayar"){
  826. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  827. }else{
  828. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  829. }
  830. }else{
  831. $response = [
  832. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  833. ];
  834. return response()->json($response, 200);
  835. }
  836. }else{
  837. if($request->remark != ''){
  838. $compound->catatan_dari_admin = $request->remark;
  839. $compound->update_by = $request->current_id;
  840. $compound->save();
  841. $saved = $compound->save();
  842. if($saved){
  843. $gDate = $compound->created_at->format('F Y');
  844. $historyData = [
  845. 'tarikh_kumpulan' => $gDate,
  846. ];
  847. $subHistory = [
  848. 'no_siri' => $compound->ConfidentialFile->no_siri,
  849. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  850. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  851. ];
  852. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  853. if(!empty($groupByDate)){
  854. $groupByDate->subhistory()->create($subHistory);
  855. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  856. }else{
  857. $history = History::create($historyData);
  858. $history->subhistory()->create($subHistory);
  859. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  860. }
  861. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  862. }else{
  863. $response = [
  864. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  865. ];
  866. return response()->json($response, 200);
  867. }
  868. }else{
  869. $response = [
  870. 'success' => false, 'message' => 'Tiada kemaskini!',
  871. ];
  872. return response()->json($response, 200);
  873. }
  874. }
  875. }
  876. }else{
  877. $response = [
  878. 'success' => false,
  879. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  880. ];
  881. return response()->json($response, 200);
  882. }
  883. }
  884. /**
  885. * Remove the specified resource from storage.
  886. *
  887. * @param int $id
  888. * @return \Illuminate\Http\Response
  889. */
  890. public function destroy($id)
  891. {
  892. //
  893. }
  894. }