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 73KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Support\Facades\Log;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Api\BaseController;
  6. use Carbon\Carbon;
  7. use App\Model\Staff;
  8. use App\Model\StaffDetail;
  9. use App\Model\Module\Compound;
  10. use App\Model\Module\Department;
  11. use App\Model\Module\DeedLaw;
  12. use App\Model\Module\Faulty;
  13. use App\Model\Module\ConfidentialFile;
  14. use App\Model\Module\History;
  15. use App\Model\Module\SubHistory;
  16. use App\Model\Module\Memo;
  17. use App\Model\Module\Attachment;
  18. use App\Jobs\StoreCompound;
  19. use App\Jobs\StoreNotice;
  20. use App\Jobs\StoreCompoundEPBT;
  21. use App\Jobs\UpdateCompoundPrice;
  22. use App\Http\Resources\CompoundResource;
  23. class CompoundResourceController extends BaseController
  24. {
  25. /**
  26. * @var ServiceCategory
  27. */
  28. protected $compound;
  29. /**
  30. * ServiceController constructor.
  31. *
  32. * @param ServiceCategory $ServiceCategory
  33. */
  34. public function __construct(Compound $compound)
  35. {
  36. $this->compound = $compound;
  37. }
  38. /**
  39. * Display a listing of the resource.
  40. *
  41. * @return \Illuminate\Http\Response
  42. */
  43. private function searchCompoundAll($jenis,$modul,$status,$start_date,$end_date,$day3, $day7){
  44. $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
  45. $start = $dateS->copy()->startOfDay();
  46. if($end_date != ''){
  47. $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
  48. $end = $dateE->copy()->endOfDay();
  49. }else{
  50. $end = $dateS->copy()->endOfDay();
  51. }
  52. if(!empty($day3))
  53. {
  54. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start->subDays(3), $end->subDays(3)));
  55. }
  56. else if(!empty($day7))
  57. {
  58. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start->subDays(7), $end->subDays(7)));
  59. }
  60. else
  61. {
  62. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start, $end));
  63. }
  64. if($modul == 'All'){
  65. $compound = $compound;
  66. }else if($modul == '06-07'){
  67. $compound = $compound->where(function($q){
  68. // $q->where(function($query){
  69. $q->where('modul', '06')->orWhere('modul','07');
  70. // });
  71. });
  72. }else {
  73. $compound = $compound->where('modul', $modul);
  74. }
  75. if($status == 'All'){
  76. $compound = $compound;
  77. }else {
  78. $compound = $compound->where('status', $status);
  79. }
  80. return $compound;
  81. }
  82. private function searchCompoundAllWithoutDate($jenis,$modul,$status,$day3, $day7){
  83. if(!empty($day3))
  84. {
  85. $compound = Compound::where('jenis', $jenis)->where('created_at', Carbon::now()->subDays(3));
  86. }
  87. else if(!empty($day7))
  88. {
  89. $compound = Compound::where('jenis', $jenis)->where('created_at', Carbon::now()->subDays(7));
  90. }
  91. else
  92. {
  93. $compound = Compound::where('jenis', $jenis);
  94. }
  95. if($modul == 'All'){
  96. $compound = $compound;
  97. }else if($modul == '06-07'){
  98. $compound = $compound->where(function($q){
  99. $q->where(function($query){
  100. $query->where('modul', '06')->orWhere('modul','07');
  101. });
  102. });
  103. }else {
  104. $compound = $compound->where('modul', $modul);
  105. }
  106. if($status == 'All'){
  107. $compound = $compound;
  108. }else {
  109. $compound = $compound->where('status', $status);
  110. }
  111. return $compound;
  112. }
  113. private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date,$day3, $day7){
  114. if(!empty($start_date)){
  115. $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date,$day3, $day7);
  116. }else{
  117. $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status,$day3, $day7);
  118. }
  119. if($enforcer == 'All'){
  120. return $compound;
  121. }else {
  122. $compound = $compound->where('dikeluarkan', $enforcer);
  123. return $compound;
  124. }
  125. }
  126. private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$day3, $day7){
  127. $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date,$day3, $day7);
  128. if($faulty == 'All'){
  129. return $compound->whereIn('jbkod',$department);
  130. }else {
  131. $compound = $compound->where('seksyen_kesalahan', $faulty);
  132. return $compound;
  133. }
  134. }
  135. private function searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$day3, $day7){
  136. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$day3, $day7);
  137. if(!empty($plate_no)){
  138. $compound = $compound->where('no_plate',$plate_no);
  139. return $compound;
  140. }else{
  141. return $compound;
  142. }
  143. }
  144. private function searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$day3, $day7){
  145. $compound = $this->searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$day3, $day7);
  146. if(!empty($kpd)){
  147. if($modul == '02'){
  148. $compound = $compound->where('kpd',$kpd)->orWhere('non', $kpd);
  149. }
  150. else{
  151. $compound = $compound->where('kpd',$kpd);
  152. }
  153. return $compound;
  154. }else{
  155. $compound = $compound->whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal']);
  156. return $compound;
  157. }
  158. }
  159. private function searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$day3, $day7){
  160. $compound = $this->searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$day3, $day7);
  161. if(!empty($company_no)){
  162. $compound = $compound->where('no_daftar_syarikat','LIKE',$company_no);
  163. return $compound;
  164. }else{
  165. return $compound;
  166. }
  167. }
  168. private function searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$day3, $day7){
  169. $compound = $this->searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$day3, $day7);
  170. if(!empty($nric)){
  171. $compound = $compound->where('identity',$nric);
  172. return $compound;
  173. }else{
  174. return $compound;
  175. }
  176. }
  177. private function searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$day3, $day7){
  178. $compound = $this->searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$day3, $day7);
  179. if(!empty($license)){
  180. $compound = $compound->where('no_akaun_lesen', 'exists', true)->where('no_akaun_lesen',$license);
  181. return $compound;
  182. }else{
  183. return $compound;
  184. }
  185. }
  186. private function searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$day3, $day7){
  187. $compound = $this->searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$day3, $day7);
  188. if(!empty($namaP)){
  189. $compound = $compound->where('nama', 'LIKE', "%{$namaP}%");
  190. return $compound;
  191. }else{
  192. return $compound;
  193. }
  194. }
  195. private function searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name,$day3, $day7){
  196. $compound = $this->searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$day3, $day7);
  197. if(!empty($company_name)){
  198. $compound = $compound->where('nama_syarikat', 'exists', true)->where('nama_syarikat', 'LIKE', '%{$company_name%}');
  199. return $compound;
  200. }else{
  201. return $compound;
  202. }
  203. }
  204. public function index(Request $request)
  205. {
  206. // $per_page = '';
  207. // $kpd = '';
  208. // $modul = '02';
  209. // $status = 'All';
  210. // $jenis = 'Pelbagai_JPB';
  211. // if(!empty($request->department)){
  212. // $department = array (
  213. // 0 => '5df355f891d6e66b9c5e626d',
  214. // 1 => '5df721c5cde7fd741433c6b2',
  215. // 2 => '5df722a24636f4594f4a3c3d',
  216. // 3 => '5f17a31795dbfd3320761bfe',
  217. // 4 => '5f3b872fea58cb3c1b0e7b8d',
  218. // );
  219. // }else {
  220. // $department = [];
  221. // }
  222. // // $start_date = '';
  223. // // $end_date = '';
  224. // $start_date = '2020-08-29';
  225. // $end_date = '2020-08-29';
  226. // $enforcer = 'All';
  227. // $faulty = 'All';
  228. // $plate_no = strtolower('');
  229. // $company_no = strtolower('');
  230. // $nric = '';
  231. // $license = '';
  232. // $namaP = '';
  233. // $company_name = '';
  234. // $day3 = 3;
  235. // $day7 = '';
  236. /////////////////////////////////////////////////////////////////////////////////
  237. $per_page = $request->per_page;
  238. $kpd = $request->kpd;
  239. $modul = $request->modul;
  240. $status = $request->status;
  241. $jenis = $request->type;
  242. if(!empty($request->department)){
  243. $department = json_decode($request->department);
  244. }else {
  245. $department = [];
  246. }
  247. $start_date = $request->start_date;
  248. $end_date = $request->end_date;
  249. $enforcer = $request->enforcer;
  250. $faulty = $request->faulty;
  251. $plate_no = strtolower($request->plate_no);
  252. $company_no = strtolower($request->company_no);
  253. $nric = $request->nric;
  254. $license = $request->license;
  255. $namaP = $request->nameP;
  256. $company_name = $request->company_name;
  257. $day3='';
  258. $day7='';
  259. if ($request->has('day3')) {
  260. $day3 = $request->day3; //has() checks if param exist and filled
  261. }
  262. if ($request->has('day7')) {
  263. $day3 = $request->day7; //has() checks if param exist and filled
  264. }
  265. // if (!empty($start_date)) {
  266. // }
  267. $nested_data = array();
  268. $compound = $this->searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name, $day3, $day7)->orderBy('created_at','ASC')->get();
  269. // info($compound);
  270. return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
  271. ->addColumn('index', function($row) {
  272. $curr = Carbon::now();
  273. $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
  274. if($curr->diffInDays($dtC) <= 3){
  275. $html = 'New';
  276. }else{ $html = ''; }
  277. return $html;
  278. })->addColumn('status_kemaskini', function($row) {
  279. $data = '';
  280. if($row['status'] == 'Berbayar'){
  281. if ($row['modul'] == '02') {
  282. $data = '<b>Selesai</b><div style="margin-top: 8px"><span></span><br/></div>';
  283. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  284. }
  285. else{
  286. $data = '<b>'.$row['status'].'</b><div style="margin-top: 8px"><span>Bayaran: </span><br/>';
  287. $data .= 'RM '.$row['amount_payment'].'</div>';
  288. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  289. }
  290. if($row['updated_by'] !== null ){
  291. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  292. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  293. }else {
  294. if(!empty($row['tarikh_bayar']) && $row['tarikh_bayar'] != ''){
  295. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  296. $data .= $row['tarikh_bayar'].' <br/>'.$row['updates_by'].'</div>';
  297. }else {
  298. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  299. $data .= $row['updated_at'].' <br/>'.$row['updates_by'].'</div>';
  300. }
  301. }
  302. }else if($row['status'] == 'Belum Bayar' && $row['updated_by'] !== null){
  303. $data = '<b>'.$row['status'].'</b>';
  304. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  305. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  306. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  307. }else if($row['status'] == 'Batal' && $row['updated_by'] !== null){
  308. $data = '<b>'.$row['status'].'</b>';
  309. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  310. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  311. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  312. }else if($row['status'] == 'Buang' && $row['updated_by'] !== null){
  313. $data = '<b>'.$row['status'].'</b>';
  314. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  315. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  316. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  317. }
  318. else
  319. {
  320. $data = $row['status'];
  321. }
  322. return $data;
  323. })->addColumn('kesalahan', function($row) {
  324. $data = '<b>Seksyen '.$row['faulty_skter'].'</b><br/>'.$row['faulty_name'];
  325. return $data;
  326. })->rawColumns(['index','status_kemaskini','kesalahan'])->make(true);
  327. }
  328. /**
  329. * Show the form for creating a new resource.
  330. *
  331. * @return \Illuminate\Http\Response
  332. */
  333. public function generateCompoundNumber($jenis, $tag)
  334. {
  335. //check if theres no 001, start fresh with 0001
  336. if (empty(Compound::where('jenis', $jenis)->where('kpd', $tag.'0001')->first())) {
  337. $kpd = '0001';
  338. }
  339. else{
  340. //check the lastest compound number stored in dbase filtered by jenis
  341. $compound = Compound::where('jenis', $jenis)->withTrashed()->latest()->first();
  342. //sanitize compound number to return only integer
  343. $kpd = filter_var($compound['kpd'], FILTER_SANITIZE_NUMBER_INT);
  344. //compulsory increment to store new compound number, WHILE number is found, keep looping
  345. do{
  346. (int)$kpd += 1;
  347. //add 0s at the fornt if number is less than 1000
  348. if ((strlen((string) $kpd)) == 1) {
  349. $kpd = '000'.$kpd;
  350. }elseif ((strlen((string)$kpd)) == 2){
  351. $kpd = '00'.$kpd;
  352. }elseif ((strlen((string)$kpd )) == 3) {
  353. $kpd = '0'.$kpd;
  354. }
  355. }while(!empty(Compound::where('jenis', $jenis)->where('kpd', $tag.$kpd)->first()));
  356. }
  357. //return kpd with tag
  358. $kpd = $tag . $kpd;
  359. return $kpd;
  360. }
  361. /**
  362. * Store a created compound from notice.
  363. *
  364. * @param \Illuminate\Http\Request $request
  365. * @return \Illuminate\Http\Response
  366. */
  367. public function store(Request $request)
  368. {
  369. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  370. if(empty($staff)){
  371. return $this->sendError('Invalid', 'Staff not existed');
  372. }else {
  373. $saved ='';
  374. $kpd = '';
  375. $no_siri = '';
  376. $data = array();
  377. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  378. if($request->jenis == 'Parkir')
  379. {
  380. if(!empty($faulty)){
  381. $countKPD = $this->compound->withTrashed()->count();
  382. do {
  383. $countKPD = $countKPD + 1;
  384. } while (!empty(Compound::where("kpd", "=", 'KP'.$countKPD)->first()));
  385. $kpd = 'KP'.$countKPD;
  386. $no_siri = date('yn').'-'.$countKPD;
  387. $fileData = [
  388. 'no_siri' => $no_siri,
  389. ];
  390. //only for compound parkir
  391. $compoundData = [
  392. 'jenis' => 'Parkir',
  393. 'kpd' => 'KPD'.$kpd,
  394. 'nama' => '-',
  395. 'identity' => '-',
  396. 'alamat' => '-',
  397. "no_plate" => strtolower($request->no_plate),
  398. "no_cukai_jalan" => $request->noCukaijalan,
  399. "jenis_kenderaan" => $request->jenisKenderaan,
  400. "model_kenderaan" => $request->modelKenderaan,
  401. "warna_kenderaan" => $request->warnakenderaan,
  402. "nama_kawasan" => $request->namaKawasan,
  403. "nama_taman" => $request->namaTaman,
  404. "nama_jalan" => $request->namaJalan,
  405. "no_parking" => $request->noParking,
  406. "catatan" => $request->catatan,
  407. "lokasi_kejadian" => '-',
  408. 'latlong' => $request->Latlong,
  409. 'jbkod' => $request->jabatan,
  410. 'akta' => $faulty->deed_law_id,
  411. 'seksyen_kesalahan' => $faulty->_id,
  412. 'jumlah_asal_kompaun' => $faulty->amount,
  413. 'jumlah_kemaskini_kompaun' => '-',
  414. 'dikeluarkan' => $staff->_id,
  415. "status" => 'Belum Bayar',
  416. "amount_payment" => '-',
  417. "receipt" => '-',
  418. "modul" => '03',
  419. "penguatkuasa" => '-',
  420. "cpn_created" => Carbon::now()->toDateTimeString(),
  421. ];
  422. $file = ConfidentialFile::create($fileData);
  423. $saved = $file->compound()->create($compoundData);
  424. }
  425. }elseif(($request->jenis == 'Pelbagai_KT') || ($request->jenis == 'Pelbagai_JPB') || ($request->jenis == 'Pelbagai_PA') || ($request->jenis == 'Pelbagai_LESEN')){
  426. $kpd = $request->kpd;
  427. $compound = Compound::where('jenis', $request->jenis)->where('kpd', $kpd)->first();
  428. info($compound);
  429. if (!empty($compound)) {
  430. $saved = '';
  431. if($compound->modul != '03')
  432. {
  433. if($request->jenis == 'Pelbagai_KT'){
  434. $compound->jenis = $request->jenis;
  435. $compound->nama = $request->namaP;
  436. $compound->identity = $request->noIc;
  437. $compound->nama_syarikat = $request->namaS;
  438. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  439. $compound->alamat = $request->alamat;
  440. $compound->no_plate = $request->no_plate;
  441. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  442. // $compound->nama_kawasan = $request->namaKawasan;
  443. // $compound->nama_taman = $request->namaTaman;
  444. // $compound->nama_jalan = $request->namaJalan;
  445. $compound->catatan = $request->catatan;
  446. $compound->latlong = $request->Latlong;
  447. // $compound->akta = $faulty->deed_law_id;
  448. // $compound->seksyen_kesalahan = $faulty->_id;
  449. // $compound->jumlah_asal_kompaun = $faulty->amount;
  450. $compound->dikeluarkan_ = $staff->_id;
  451. $compound->status = 'Belum Bayar';
  452. $compound->modul = '03';
  453. $compound->no_telefon = $request->tel;
  454. $compound->no_akaun_lesen = $request->lesen;
  455. $compound->cpn_created = Carbon::now()->toDateTimeString();
  456. }elseif($request->jenis == 'Pelbagai_JPB'){
  457. $compound->jenis = $request->jenis;
  458. $compound->nama = $request->namaP;
  459. $compound->identity = $request->noIc;
  460. $compound->nama_syarikat = $request->namaS;
  461. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  462. $compound->alamat = $request->alamat;
  463. $compound->no_plate = $request->no_plate;
  464. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  465. // $compound->nama_kawasan => $request->namaKawasan;
  466. // $compound->nama_taman => $request->namaTaman;
  467. // $compound->nama_jalan => $request->namaJalan;
  468. $compound->catatan = $request->catatan;
  469. $compound->latlong = $request->Latlong;
  470. // $compound->akta => $faulty->deed_law_id;
  471. // $compound->seksyen_kesalahan => $faulty->_id;
  472. // $compound->jumlah_asal_kompaun => $faulty->amount;
  473. $compound->dikeluarkan_ = $staff->_id;
  474. $compound->status = 'Belum Bayar';
  475. $compound->modul = '03';
  476. $compound->no_telefon = $request->tel;
  477. $compound->no_akaun_lesen = $request->lesen;
  478. $compound->cpn_created = Carbon::now()->toDateTimeString();
  479. }elseif($request->jenis == 'Pelbagai_PA'){
  480. $compound->jenis = $request->jenis;
  481. $compound->nama = $request->namaP;
  482. $compound->identity = $request->noIc;
  483. $compound->nama_syarikat = $request->namaS;
  484. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  485. $compound->alamat = $request->alamat;
  486. $compound->no_plate = $request->no_plate;
  487. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  488. // $compound->nama_kawasan = $request->namaKawasan;
  489. // $compound->nama_taman = $request->namaTaman;
  490. // $compound->nama_jalan = $request->namaJalan;
  491. $compound->catatan = $request->catatan;
  492. $compound->latlong = $request->Latlong;
  493. // $compound->akta = $faulty->deed_law_id;
  494. // $compound->seksyen_kesalahan = $faulty->_id;
  495. // $compound->jumlah_asal_kompaun = $faulty->amount;
  496. $compound->dikeluarkan_ = $staff->_id;
  497. $compound->status = 'Belum Bayar';
  498. $compound->modul = '03';
  499. $compound->no_telefon = $request->tel;
  500. $compound->no_akaun_lesen = $request->lesen;
  501. $compound->bil_haiwan = $request->lesen;
  502. $compound->cpn_created = Carbon::now()->toDateTimeString();
  503. }elseif($request->jenis == 'Pelbagai_LESEN'){
  504. $compound->jenis = $request->jenis;
  505. $compound->nama = $request->namaP;
  506. $compound->identity = $request->noIc;
  507. $compound->nama_syarikat = $request->namaS;
  508. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  509. $compound->alamat = $request->alamat;
  510. $compound->no_plate = $request->no_plate;
  511. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  512. // $compound->nama_kawasan = $request->namaKawasan;
  513. // $compound->nama_taman = $request->namaTaman;
  514. // $compound->nama_jalan = $request->namaJalan;
  515. $compound->catatan = $request->catatan;
  516. $compound->latlong = $request->Latlong;
  517. // $compound->akta = $faulty->deed_law_id;
  518. // $compound->seksyen_kesalahan = $faulty->_id;
  519. // $compound->jumlah_asal_kompaun = $faulty->amount;
  520. $compound->dikeluarkan_ = $staff->_id;
  521. $compound->status = 'Belum Bayar';
  522. $compound->modul = '03';
  523. $compound->no_telefon = $request->tel;
  524. $compound->no_akaun_lesen = $request->lesen;
  525. $compound->cpn_created = Carbon::now()->toDateTimeString();
  526. }
  527. $saved = $compound->save();
  528. }
  529. else
  530. {
  531. return $this->sendResponse('', 'Kompaun ini telah dikeluarkan!');
  532. }
  533. if($saved){
  534. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  535. // if(!empty($compound)){
  536. dispatch(new UpdateCompoundPrice($kpd));
  537. // $tawaran = '';
  538. // if($compound->jumlah_kemaskini_kompaun != ''){
  539. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  540. // }else{
  541. // $tawaran = $compound->jumlah_asal_kompaun;
  542. // }
  543. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  544. array_push($data, array('kpd' => $kpd));
  545. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  546. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  547. // }
  548. }
  549. }
  550. else{
  551. return $this->sendResponse('', 'Kompaun ini tidak dijumpai!');
  552. }
  553. }
  554. }
  555. }
  556. /**
  557. *
  558. * Store a newly created notice
  559. *
  560. **/
  561. public function storeNewNotice(Request $request)
  562. {
  563. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  564. if(empty($staff)){
  565. return $this->sendError('Invalid', 'Staff not existed');
  566. }else {
  567. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  568. if(!empty($faulty)){
  569. $data = array();
  570. $kpd = '';
  571. $no_siri ='';
  572. // $countKPD = $this->compound->withTrashed()->count(); //for parking numbering
  573. // do {
  574. // $kpd = $kpd + 1;
  575. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  576. // $kpd = 'KP'.$countKPD;
  577. // $no_siri = date('yn').'-'.$countKPD;
  578. // $fileData = [
  579. // 'no_siri' => $no_siri,
  580. // ];
  581. if($request->jenis == 'Parkir'){
  582. //for compound numbering
  583. $countKPD = $this->compound->withTrashed()->count();
  584. $no_siri = date('yn').'-'.$countKPD.'-0';
  585. $compoundData = [
  586. 'jenis' => 'Parkir',
  587. 'kpd' => 'KPD'.$countKPD,
  588. 'nama' => '-',
  589. 'identity' => '-',
  590. 'alamat' => '-',
  591. "no_plate" => strtolower($request->no_plate),
  592. "no_cukai_jalan" => $request->noCukaijalan,
  593. "jenis_kenderaan" => $request->jenisKenderaan,
  594. "model_kenderaan" => $request->modelKenderaan,
  595. "warna_kenderaan" => $request->warnakenderaan,
  596. "nama_kawasan" => $request->namaKawasan,
  597. "nama_taman" => $request->namaTaman,
  598. "nama_jalan" => $request->namaJalan,
  599. "no_parking" => $request->noParking,
  600. "catatan" => $request->catatan,
  601. "lokasi_kejadian" => '-',
  602. 'latlong' => $request->Latlong,
  603. 'jbkod' => $request->jabatan,
  604. 'akta' => $faulty->deed_law_id,
  605. 'seksyen_kesalahan' => $faulty->_id,
  606. 'jumlah_asal_kompaun' => $faulty->amount,
  607. 'jumlah_kemaskini_kompaun' => '-',
  608. 'dikeluarkan' => $staff->_id,
  609. "status" => 'Belum Bayar',
  610. "amount_payment" => '-',
  611. "receipt" => '-',
  612. "modul" => $request->modul,
  613. "penguatkuasa" => '-',
  614. "notis_created" => Carbon::now()->toDateTimeString(),
  615. ];
  616. }elseif($request->jenis == 'Pelbagai_KT'){
  617. $kpd = $this->generateCompoundNumber($request->jenis, 'KT');
  618. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  619. $compoundData = [
  620. 'jenis' => $request->jenis,
  621. 'kpd' => $kpd,
  622. 'non' => 'NKG'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT),
  623. 'nama' => $request->namaP,
  624. 'identity' => $request->noIc,
  625. 'nama_syarikat' => $request->namaS,
  626. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  627. 'alamat' => $request->alamat,
  628. "no_plate" => $request->no_plate,
  629. "no_cukai_jalan" => $request->no_cukai_jalan,
  630. "nama_kawasan" => $request->namaKawasan,
  631. "nama_taman" => $request->namaTaman,
  632. "nama_jalan" => $request->namaJalan,
  633. "catatan" => $request->catatan,
  634. "lokasi_kejadian" => '-',
  635. 'latlong' => $request->Latlong,
  636. 'jbkod' => $request->jabatan,
  637. 'akta' => $faulty->deed_law_id,
  638. 'seksyen_kesalahan' => $faulty->_id,
  639. 'jumlah_asal_kompaun' => $faulty->amount,
  640. 'jumlah_kemaskini_kompaun' => '-',
  641. 'dikeluarkan' => $staff->_id,
  642. "status" => 'Belum Bayar',
  643. "amount_payment" => '-',
  644. "receipt" => '-',
  645. "modul" => $request->modul,
  646. "penguatkuasa" => '-',
  647. "no_telefon" => $request->tel,
  648. "no_akaun_lesen" => $request->lesen,
  649. "maklumat_tambahan" => '-',
  650. "tindakan" => $request->tindakan,
  651. "tempoh" => $request->tempoh,
  652. "notis_created" => Carbon::now()->toDateTimeString(),
  653. ];
  654. }elseif($request->jenis == 'Pelbagai_JPB'){
  655. $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  656. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  657. $compoundData = [
  658. 'jenis' => $request->jenis,
  659. 'kpd' => $kpd,
  660. 'non' => 'NMH'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT),
  661. 'nama' => $request->namaP,
  662. 'identity' => $request->noIc,
  663. 'nama_syarikat' => $request->namaS,
  664. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  665. 'alamat' => $request->alamat,
  666. "no_plate" => $request->no_plate,
  667. "no_cukai_jalan" => $request->no_cukai_jalan,
  668. "nama_kawasan" => $request->namaKawasan,
  669. "nama_taman" => $request->namaTaman,
  670. "nama_jalan" => $request->namaJalan,
  671. "catatan" => $request->catatan,
  672. "lokasi_kejadian" => '-',
  673. 'latlong' => $request->Latlong,
  674. 'jbkod' => $request->jabatan,
  675. 'akta' => $faulty->deed_law_id,
  676. 'seksyen_kesalahan' => $faulty->_id,
  677. 'jumlah_asal_kompaun' => $faulty->amount,
  678. 'jumlah_kemaskini_kompaun' => '-',
  679. 'dikeluarkan' => $staff->_id,
  680. "status" => 'Belum Bayar',
  681. "amount_payment" => '-',
  682. "receipt" => '-',
  683. "modul" => $request->modul,
  684. "penguatkuasa" => '-',
  685. "no_telefon" => $request->tel,
  686. "no_akaun_lesen" => $request->lesen,
  687. "maklumat_tambahan" => '-',
  688. "tindakan" => $request->tindakan,
  689. "tempoh" => $request->tempoh,
  690. "notis_created" => Carbon::now()->toDateTimeString(),
  691. ];
  692. }
  693. elseif($request->jenis == 'Pelbagai_LESEN'){
  694. //HN bcs other N stands for notice. compound number no need front N
  695. $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  696. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-3';
  697. $compoundData = [
  698. 'jenis' => $request->jenis,
  699. 'kpd' => $kpd,
  700. 'non' => 'NHN'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT),
  701. 'nama' => $request->namaP,
  702. 'identity' => $request->noIc,
  703. 'nama_syarikat' => $request->namaS,
  704. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  705. 'alamat' => $request->alamat,
  706. "no_plate" => $request->no_plate,
  707. "no_cukai_jalan" => $request->no_cukai_jalan,
  708. "nama_kawasan" => $request->namaKawasan,
  709. "nama_taman" => $request->namaTaman,
  710. "nama_jalan" => $request->namaJalan,
  711. "catatan" => $request->catatan,
  712. "lokasi_kejadian" => '-',
  713. 'latlong' => $request->Latlong,
  714. 'jbkod' => $request->jabatan,
  715. 'akta' => $faulty->deed_law_id,
  716. 'seksyen_kesalahan' => $faulty->_id,
  717. 'jumlah_asal_kompaun' => $faulty->amount,
  718. 'jumlah_kemaskini_kompaun' => '-',
  719. 'dikeluarkan' => $staff->_id,
  720. "status" => 'Belum Bayar',
  721. "amount_payment" => '-',
  722. "receipt" => '-',
  723. "modul" => $request->modul,
  724. "penguatkuasa" => '-',
  725. "no_telefon" => $request->tel,
  726. "no_akaun_lesen" => $request->lesen,
  727. "maklumat_tambahan" => '-',
  728. "notis_created" => Carbon::now()->toDateTimeString(),
  729. ];
  730. }
  731. elseif($request->jenis == 'Pelbagai_PA'){
  732. $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  733. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-4';
  734. $compoundData = [
  735. 'jenis' => $request->jenis,
  736. 'kpd' => $kpd,
  737. 'non' => 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT),
  738. 'nama' => $request->namaP,
  739. 'identity' => $request->noIc,
  740. 'nama_syarikat' => $request->namaS,
  741. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  742. 'alamat' => $request->alamat,
  743. "no_plate" => $request->no_plate,
  744. "no_cukai_jalan" => $request->no_cukai_jalan,
  745. "nama_kawasan" => $request->namaKawasan,
  746. "nama_taman" => $request->namaTaman,
  747. "nama_jalan" => $request->namaJalan,
  748. "catatan" => $request->catatan,
  749. "lokasi_kejadian" => '-',
  750. 'latlong' => $request->Latlong,
  751. 'jbkod' => $request->jabatan,
  752. 'akta' => $faulty->deed_law_id,
  753. 'seksyen_kesalahan' => $faulty->_id,
  754. 'jumlah_asal_kompaun' => $faulty->amount,
  755. 'jumlah_kemaskini_kompaun' => '-',
  756. 'dikeluarkan' => $staff->_id,
  757. "status" => 'Belum Bayar',
  758. "amount_payment" => '-',
  759. "receipt" => '-',
  760. "modul" => $request->modul,
  761. "penguatkuasa" => '-',
  762. "no_telefon" => $request->tel,
  763. "no_akaun_lesen" => $request->lesen,
  764. "maklumat_tambahan" => '-',
  765. "bil_haiwan" => $request->bil_haiwan,
  766. "notis_created" => Carbon::now()->toDateTimeString(),
  767. ];
  768. }
  769. $fileData = [
  770. 'no_siri' => $no_siri,
  771. ];
  772. $file = ConfidentialFile::create($fileData);
  773. $saved = $file->compound()->create($compoundData);
  774. if($saved){
  775. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  776. // if(!empty($compound)){
  777. dispatch(new UpdateCompoundPrice($kpd));
  778. // $tawaran = '';
  779. // if($compound->jumlah_kemaskini_kompaun != ''){
  780. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  781. // }else{
  782. // $tawaran = $compound->jumlah_asal_kompaun;
  783. // }
  784. $this->dispatch(new StoreNotice($request->all(), $kpd, $staff->_id, $no_siri));
  785. array_push($data, array('kpd' => $kpd));
  786. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  787. // }
  788. }
  789. }
  790. }
  791. }
  792. /**
  793. * Store a newly created compound (parkir, KT, JPB).
  794. *
  795. * @param \Illuminate\Http\Request $request
  796. * @return \Illuminate\Http\Response
  797. */
  798. public function storeNewCompound(Request $request)
  799. {
  800. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  801. if(empty($staff)){
  802. return $this->sendError('Invalid', 'Staff not existed');
  803. }else {
  804. $data = array();
  805. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  806. if(!empty($faulty)){
  807. $kpd = '';
  808. $no_siri ='';
  809. // $countKPD = $this->compound->withTrashed()->count();
  810. // do {
  811. // $countKPD = $countKPD + 1;
  812. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  813. // $kpd = $countKPD;
  814. // $no_siri = date('yn').'-'.$countKPD;
  815. // $fileData = [
  816. // 'no_siri' => $no_siri,
  817. // ];
  818. if($request->jenis == 'Parkir')
  819. {
  820. //for compound numbering
  821. $countKPD = $this->compound->withTrashed()->count();
  822. $no_siri = date('yn').'-'.$countKPD.'-0';
  823. //only for compound parkir
  824. $compoundData = [
  825. 'jenis' => 'Parkir',
  826. 'kpd' => 'KPD'.$countKPD,
  827. 'nama' => '-',
  828. 'identity' => '-',
  829. 'alamat' => '-',
  830. "no_plate" => strtolower($request->no_plate),
  831. "no_cukai_jalan" => $request->noCukaijalan,
  832. "jenis_kenderaan" => $request->jenisKenderaan,
  833. "model_kenderaan" => $request->modelKenderaan,
  834. "warna_kenderaan" => $request->warnakenderaan,
  835. "nama_kawasan" => $request->namaKawasan,
  836. "nama_taman" => $request->namaTaman,
  837. "nama_jalan" => $request->namaJalan,
  838. "no_parking" => $request->noParking,
  839. "catatan" => $request->catatan,
  840. "lokasi_kejadian" => '-',
  841. 'latlong' => $request->Latlong,
  842. 'jbkod' => $request->jabatan,
  843. 'akta' => $faulty->deed_law_id,
  844. 'seksyen_kesalahan' => $faulty->_id,
  845. 'jumlah_asal_kompaun' => $faulty->amount,
  846. 'jumlah_kemaskini_kompaun' => '-',
  847. 'dikeluarkan' => $staff->_id,
  848. "status" => 'Belum Bayar',
  849. "amount_payment" => '-',
  850. "receipt" => '-',
  851. "modul" => '03',
  852. "penguatkuasa" => '-',
  853. "cpn_created" => Carbon::now()->toDateTimeString(),
  854. ];
  855. }
  856. if ($request->jenis == 'Pelbagai_KT') {
  857. $kpd = $this->generateCompoundNumber($request->jenis, 'KT');
  858. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  859. $compoundData = [
  860. 'jenis' => $request->jenis,
  861. 'kpd' => $kpd,
  862. 'nama' => $request->namaP,
  863. 'identity' => $request->noIc,
  864. 'nama_syarikat' => $request->namaS,
  865. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  866. 'alamat' => $request->alamat,
  867. "no_plate" => $request->no_plate,
  868. "no_cukai_jalan" => $request->no_cukai_jalan,
  869. "nama_kawasan" => $request->namaKawasan,
  870. "nama_taman" => $request->namaTaman,
  871. "nama_jalan" => $request->namaJalan,
  872. "catatan" => $request->catatan,
  873. "lokasi_kejadian" => '-',
  874. 'latlong' => $request->Latlong,
  875. 'jbkod' => $request->jabatan,
  876. 'akta' => $faulty->deed_law_id,
  877. 'seksyen_kesalahan' => $faulty->_id,
  878. 'jumlah_asal_kompaun' => $faulty->amount,
  879. 'jumlah_kemaskini_kompaun' => '-',
  880. 'dikeluarkan' => $staff->_id,
  881. "status" => 'Belum Bayar',
  882. "amount_payment" => '-',
  883. "receipt" => '-',
  884. "modul" => $request->modul,
  885. "penguatkuasa" => '-',
  886. "no_telefon" => $request->tel,
  887. "no_akaun_lesen" => $request->lesen,
  888. "maklumat_tambahan" => '-',
  889. "tindakan" => '-',
  890. "tempoh" => '-',
  891. "cpn_created" => Carbon::now()->toDateTimeString(),
  892. ];
  893. }
  894. elseif ($request->jenis == 'Pelbagai_JPB') {
  895. $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  896. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  897. $compoundData = [
  898. 'jenis' => $request->jenis,
  899. 'kpd' => $kpd,
  900. 'nama' => $request->namaP,
  901. 'identity' => $request->noIc,
  902. 'nama_syarikat' => $request->namaS,
  903. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  904. 'alamat' => $request->alamat,
  905. "no_plate" => $request->no_plate,
  906. "no_cukai_jalan" => $request->no_cukai_jalan,
  907. "nama_kawasan" => $request->namaKawasan,
  908. "nama_taman" => $request->namaTaman,
  909. "nama_jalan" => $request->namaJalan,
  910. "catatan" => $request->catatan,
  911. "lokasi_kejadian" => '-',
  912. 'latlong' => $request->Latlong,
  913. 'jbkod' => $request->jabatan,
  914. 'akta' => $faulty->deed_law_id,
  915. 'seksyen_kesalahan' => $faulty->_id,
  916. 'jumlah_asal_kompaun' => $faulty->amount,
  917. 'jumlah_kemaskini_kompaun' => '-',
  918. 'dikeluarkan' => $staff->_id,
  919. "status" => 'Belum Bayar',
  920. "amount_payment" => '-',
  921. "receipt" => '-',
  922. "modul" => $request->modul,
  923. "penguatkuasa" => '-',
  924. "no_telefon" => $request->tel,
  925. "no_akaun_lesen" => $request->lesen,
  926. "maklumat_tambahan" => '-',
  927. "tindakan" => '-',
  928. "tempoh" => '-',
  929. "cpn_created" => Carbon::now()->toDateTimeString(),
  930. ];
  931. }
  932. elseif ($request->jenis == 'Pelbagai_LESEN') {
  933. //HN bcs other N stands for notice. compound number no need front N
  934. $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  935. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-3';
  936. $compoundData = [
  937. 'jenis' => $request->jenis,
  938. 'kpd' => $kpd,
  939. 'nama' => $request->namaP,
  940. 'identity' => $request->noIc,
  941. 'nama_syarikat' => $request->namaS,
  942. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  943. 'alamat' => $request->alamat,
  944. "no_plate" => $request->no_plate,
  945. "no_cukai_jalan" => $request->no_cukai_jalan,
  946. "nama_kawasan" => $request->namaKawasan,
  947. "nama_taman" => $request->namaTaman,
  948. "nama_jalan" => $request->namaJalan,
  949. "catatan" => $request->catatan,
  950. "lokasi_kejadian" => '-',
  951. 'latlong' => $request->Latlong,
  952. 'jbkod' => $request->jabatan,
  953. 'akta' => $faulty->deed_law_id,
  954. 'seksyen_kesalahan' => $faulty->_id,
  955. 'jumlah_asal_kompaun' => $faulty->amount,
  956. 'jumlah_kemaskini_kompaun' => '-',
  957. 'dikeluarkan' => $staff->_id,
  958. "status" => 'Belum Bayar',
  959. "amount_payment" => '-',
  960. "receipt" => '-',
  961. "modul" => $request->modul,
  962. "penguatkuasa" => '-',
  963. "no_telefon" => $request->tel,
  964. "no_akaun_lesen" => $request->lesen,
  965. "maklumat_tambahan" => '-',
  966. "cpn_created" => Carbon::now()->toDateTimeString(),
  967. ];
  968. }
  969. else if($request->jenis == 'Pelbagai_PA'){
  970. $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  971. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-4';
  972. $compoundData = [
  973. 'jenis' => $request->jenis,
  974. 'kpd' => $kpd,
  975. 'nama' => $request->namaP,
  976. 'identity' => $request->noIc,
  977. 'nama_syarikat' => $request->namaS,
  978. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  979. 'alamat' => $request->alamat,
  980. "no_plate" => $request->no_plate,
  981. "no_cukai_jalan" => $request->no_cukai_jalan,
  982. "nama_kawasan" => $request->namaKawasan,
  983. "nama_taman" => $request->namaTaman,
  984. "nama_jalan" => $request->namaJalan,
  985. "catatan" => $request->catatan,
  986. "lokasi_kejadian" => '-',
  987. 'latlong' => $request->Latlong,
  988. 'jbkod' => $request->jabatan,
  989. 'akta' => $faulty->deed_law_id,
  990. 'seksyen_kesalahan' => $faulty->_id,
  991. 'jumlah_asal_kompaun' => $faulty->amount,
  992. 'jumlah_kemaskini_kompaun' => '-',
  993. 'dikeluarkan' => $staff->_id,
  994. "status" => 'Belum Bayar',
  995. "amount_payment" => '-',
  996. "receipt" => '-',
  997. "modul" => $request->modul,
  998. "penguatkuasa" => '-',
  999. "no_telefon" => $request->tel,
  1000. "no_akaun_lesen" => $request->lesen,
  1001. "maklumat_tambahan" => '-',
  1002. "bil_haiwan" => $request->bil_haiwan,
  1003. "cpn_created" => Carbon::now()->toDateTimeString(),
  1004. ];
  1005. }
  1006. $fileData = [
  1007. 'no_siri' => $no_siri,
  1008. ];
  1009. $file = ConfidentialFile::create($fileData);
  1010. $saved = $file->compound()->create($compoundData);
  1011. if($saved){
  1012. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  1013. // if(!empty($compound)){
  1014. dispatch(new UpdateCompoundPrice($kpd));
  1015. // $tawaran = '';
  1016. // if($compound->jumlah_kemaskini_kompaun != ''){
  1017. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  1018. // }else{
  1019. // $tawaran = $compound->jumlah_asal_kompaun;
  1020. // }
  1021. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  1022. array_push($data, array('kpd' => $kpd));
  1023. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  1024. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  1025. }
  1026. }
  1027. return $this->sendResponse('Tidak Berjaya!', 'Kesalahan tidak dijumpai!');
  1028. }
  1029. }
  1030. /**
  1031. * Display the specified resource.
  1032. *
  1033. * @param int $id
  1034. * @return \Illuminate\Http\Response
  1035. */
  1036. public function show($id)
  1037. {
  1038. //
  1039. }
  1040. /**
  1041. * Show the form for editing the specified resource.
  1042. *
  1043. * @param int $id
  1044. * @return \Illuminate\Http\Response
  1045. */
  1046. public function edit($id)
  1047. {
  1048. //
  1049. }
  1050. /**
  1051. * Update the specified resource in storage.
  1052. *
  1053. * @param \Illuminate\Http\Request $request
  1054. * @param int $id
  1055. * @return \Illuminate\Http\Response
  1056. */
  1057. public function update(Request $request, $id)
  1058. {
  1059. //
  1060. }
  1061. public function updateStatusNoticeViaDashboard(Request $request)
  1062. {
  1063. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1064. $staff = StaffDetail::find($request->current_id);
  1065. if(!empty($compound) && !empty($staff)){
  1066. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1067. if($compound->status != $request->status){
  1068. $compound->status = $request->status;
  1069. $compound->catatan_dari_admin = $request->remark;
  1070. $compound->update_by = $request->current_id;
  1071. $saved = $compound->save();
  1072. if($saved){
  1073. $gDate = $compound->created_at->format('F Y');
  1074. $historyData = [
  1075. 'tarikh_kumpulan' => $gDate,
  1076. ];
  1077. $subHistory = [
  1078. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1079. 'tajuk' => "Status notis ".$compound->kpd. " telah dikemaskini",
  1080. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1081. ];
  1082. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1083. if(!empty($groupByDate)){
  1084. $groupByDate->subhistory()->create($subHistory);
  1085. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1086. }else{
  1087. $history = History::create($historyData);
  1088. $history->subhistory()->create($subHistory);
  1089. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1090. }
  1091. if($request->status == "Berbayar"){
  1092. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1093. }else{
  1094. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1095. }
  1096. }else{
  1097. $response = [
  1098. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1099. ];
  1100. return response()->json($response, 200);
  1101. }
  1102. }else{
  1103. if($request->remark != ''){
  1104. $compound->catatan_dari_admin = $request->remark;
  1105. $compound->update_by = $request->current_id;
  1106. $compound->save();
  1107. $saved = $compound->save();
  1108. if($saved){
  1109. $gDate = $compound->created_at->format('F Y');
  1110. $historyData = [
  1111. 'tarikh_kumpulan' => $gDate,
  1112. ];
  1113. $subHistory = [
  1114. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1115. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1116. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1117. ];
  1118. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1119. if(!empty($groupByDate)){
  1120. $groupByDate->subhistory()->create($subHistory);
  1121. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1122. }else{
  1123. $history = History::create($historyData);
  1124. $history->subhistory()->create($subHistory);
  1125. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1126. }
  1127. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1128. }else{
  1129. $response = [
  1130. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1131. ];
  1132. return response()->json($response, 200);
  1133. }
  1134. }else{
  1135. $response = [
  1136. 'success' => false, 'message' => 'Tiada kemaskini!',
  1137. ];
  1138. return response()->json($response, 200);
  1139. }
  1140. }
  1141. }else{
  1142. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1143. $compound->status = $request->status;
  1144. $compound->catatan_dari_admin = $request->remark;
  1145. // $compound->amount_payment = $request->amount;
  1146. $compound->update_by = $request->current_id;
  1147. $saved = $compound->save();
  1148. if($saved){
  1149. $gDate = $compound->created_at->format('F Y');
  1150. $historyData = [
  1151. 'tarikh_kumpulan' => $gDate,
  1152. ];
  1153. $subHistory = [
  1154. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1155. 'tajuk' => "Status notis telah dikemaskini",
  1156. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1157. ];
  1158. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1159. if(!empty($groupByDate)){
  1160. $groupByDate->subhistory()->create($subHistory);
  1161. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1162. }else{
  1163. $history = History::create($historyData);
  1164. $history->subhistory()->create($subHistory);
  1165. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1166. }
  1167. if($request->status == "Berbayar"){
  1168. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1169. }else{
  1170. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1171. }
  1172. }else{
  1173. $response = [
  1174. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1175. ];
  1176. return response()->json($response, 200);
  1177. }
  1178. }else{
  1179. if($request->remark != ''){
  1180. $compound->catatan_dari_admin = $request->remark;
  1181. $compound->update_by = $request->current_id;
  1182. $compound->save();
  1183. $saved = $compound->save();
  1184. if($saved){
  1185. $gDate = $compound->created_at->format('F Y');
  1186. $historyData = [
  1187. 'tarikh_kumpulan' => $gDate,
  1188. ];
  1189. $subHistory = [
  1190. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1191. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1192. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1193. ];
  1194. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1195. if(!empty($groupByDate)){
  1196. $groupByDate->subhistory()->create($subHistory);
  1197. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1198. }else{
  1199. $history = History::create($historyData);
  1200. $history->subhistory()->create($subHistory);
  1201. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1202. }
  1203. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1204. }else{
  1205. $response = [
  1206. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1207. ];
  1208. return response()->json($response, 200);
  1209. }
  1210. }else{
  1211. $response = [
  1212. 'success' => false, 'message' => 'Tiada kemaskini!',
  1213. ];
  1214. return response()->json($response, 200);
  1215. }
  1216. }
  1217. }
  1218. }else{
  1219. $response = [
  1220. 'success' => false,
  1221. 'message' => 'Notis ini tidak dijumpai / staff tidak ditemui',
  1222. ];
  1223. return response()->json($response, 200);
  1224. }
  1225. }
  1226. public function updateStatusPaymentViaDashboard(Request $request)
  1227. {
  1228. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1229. $staff = StaffDetail::find($request->current_id);
  1230. if(!empty($compound) && !empty($staff)){
  1231. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1232. if($compound->status != $request->status){
  1233. $compound->status = $request->status;
  1234. $compound->catatan_dari_admin = $request->remark;
  1235. $compound->amount_payment = $request->amount;
  1236. $compound->update_by = $request->current_id;
  1237. $saved = $compound->save();
  1238. if($saved){
  1239. $gDate = $compound->created_at->format('F Y');
  1240. $historyData = [
  1241. 'tarikh_kumpulan' => $gDate,
  1242. ];
  1243. $subHistory = [
  1244. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1245. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1246. '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>",
  1247. ];
  1248. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1249. if(!empty($groupByDate)){
  1250. $groupByDate->subhistory()->create($subHistory);
  1251. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1252. }else{
  1253. $history = History::create($historyData);
  1254. $history->subhistory()->create($subHistory);
  1255. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1256. }
  1257. if($request->status == "Berbayar"){
  1258. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1259. }else{
  1260. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1261. }
  1262. }else{
  1263. $response = [
  1264. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1265. ];
  1266. return response()->json($response, 200);
  1267. }
  1268. }else{
  1269. if($request->remark != ''){
  1270. $compound->catatan_dari_admin = $request->remark;
  1271. $compound->update_by = $request->current_id;
  1272. $compound->save();
  1273. $saved = $compound->save();
  1274. if($saved){
  1275. $gDate = $compound->created_at->format('F Y');
  1276. $historyData = [
  1277. 'tarikh_kumpulan' => $gDate,
  1278. ];
  1279. $subHistory = [
  1280. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1281. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1282. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1283. ];
  1284. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1285. if(!empty($groupByDate)){
  1286. $groupByDate->subhistory()->create($subHistory);
  1287. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1288. }else{
  1289. $history = History::create($historyData);
  1290. $history->subhistory()->create($subHistory);
  1291. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1292. }
  1293. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1294. }else{
  1295. $response = [
  1296. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1297. ];
  1298. return response()->json($response, 200);
  1299. }
  1300. }else{
  1301. $response = [
  1302. 'success' => false, 'message' => 'Tiada kemaskini!',
  1303. ];
  1304. return response()->json($response, 200);
  1305. }
  1306. }
  1307. }else{
  1308. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1309. $compound->status = $request->status;
  1310. $compound->catatan_dari_admin = $request->remark;
  1311. $compound->amount_payment = $request->amount;
  1312. $compound->update_by = $request->current_id;
  1313. $saved = $compound->save();
  1314. if($saved){
  1315. $gDate = $compound->created_at->format('F Y');
  1316. $historyData = [
  1317. 'tarikh_kumpulan' => $gDate,
  1318. ];
  1319. $subHistory = [
  1320. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1321. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1322. '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>",
  1323. ];
  1324. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1325. if(!empty($groupByDate)){
  1326. $groupByDate->subhistory()->create($subHistory);
  1327. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1328. }else{
  1329. $history = History::create($historyData);
  1330. $history->subhistory()->create($subHistory);
  1331. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1332. }
  1333. if($request->status == "Berbayar"){
  1334. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1335. }else{
  1336. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1337. }
  1338. }else{
  1339. $response = [
  1340. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1341. ];
  1342. return response()->json($response, 200);
  1343. }
  1344. }else{
  1345. if($request->remark != ''){
  1346. $compound->catatan_dari_admin = $request->remark;
  1347. $compound->update_by = $request->current_id;
  1348. $compound->save();
  1349. $saved = $compound->save();
  1350. if($saved){
  1351. $gDate = $compound->created_at->format('F Y');
  1352. $historyData = [
  1353. 'tarikh_kumpulan' => $gDate,
  1354. ];
  1355. $subHistory = [
  1356. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1357. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1358. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1359. ];
  1360. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1361. if(!empty($groupByDate)){
  1362. $groupByDate->subhistory()->create($subHistory);
  1363. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1364. }else{
  1365. $history = History::create($historyData);
  1366. $history->subhistory()->create($subHistory);
  1367. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1368. }
  1369. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1370. }else{
  1371. $response = [
  1372. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1373. ];
  1374. return response()->json($response, 200);
  1375. }
  1376. }else{
  1377. $response = [
  1378. 'success' => false, 'message' => 'Tiada kemaskini!',
  1379. ];
  1380. return response()->json($response, 200);
  1381. }
  1382. }
  1383. }
  1384. }else{
  1385. $response = [
  1386. 'success' => false,
  1387. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  1388. ];
  1389. return response()->json($response, 200);
  1390. }
  1391. }
  1392. /**
  1393. * Remove the specified resource from storage.
  1394. *
  1395. * @param int $id
  1396. * @return \Illuminate\Http\Response
  1397. */
  1398. public function destroy($id)
  1399. {
  1400. //
  1401. }
  1402. }