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

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