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

CompoundResourceController.php 74KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666
  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-09-29';
  225. // $end_date = '2020-10-01';
  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 = $request->seksyen;
  378. $faulty = Faulty::where('_id',$request->get('seksyen'))->orWhere('nama', 'like', $faulty)->first();
  379. if($request->jenis == 'Parkir')
  380. {
  381. if(!empty($faulty)){
  382. $countKPD = $this->compound->withTrashed()->count();
  383. do {
  384. $countKPD = $countKPD + 1;
  385. } while (!empty(Compound::where("kpd", "=", 'KP'.$countKPD)->first()));
  386. $kpd = 'KP'.$countKPD;
  387. $no_siri = date('yn').'-'.$countKPD;
  388. $fileData = [
  389. 'no_siri' => $no_siri,
  390. ];
  391. //only for compound parkir
  392. $compoundData = [
  393. 'jenis' => 'Parkir',
  394. 'kpd' => 'KPD'.$kpd,
  395. 'nama' => '-',
  396. 'identity' => '-',
  397. 'alamat' => '-',
  398. "no_plate" => strtolower($request->no_plate),
  399. "no_cukai_jalan" => $request->noCukaijalan,
  400. "jenis_kenderaan" => $request->jenisKenderaan,
  401. "model_kenderaan" => $request->modelKenderaan,
  402. "warna_kenderaan" => $request->warnakenderaan,
  403. "nama_kawasan" => $request->namaKawasan,
  404. "nama_taman" => $request->namaTaman,
  405. "nama_jalan" => $request->namaJalan,
  406. "no_parking" => $request->noParking,
  407. "catatan" => $request->catatan,
  408. "lokasi_kejadian" => '-',
  409. 'latlong' => $request->Latlong,
  410. 'jbkod' => $request->jabatan,
  411. 'akta' => $faulty->deed_law_id,
  412. 'seksyen_kesalahan' => $faulty->_id,
  413. 'jumlah_asal_kompaun' => $faulty->amount,
  414. 'jumlah_kemaskini_kompaun' => '-',
  415. 'dikeluarkan' => $staff->_id,
  416. "status" => 'Belum Bayar',
  417. "amount_payment" => '-',
  418. "receipt" => '-',
  419. "modul" => '03',
  420. "penguatkuasa" => '-',
  421. "cpn_created" => Carbon::now()->toDateTimeString(),
  422. ];
  423. $file = ConfidentialFile::create($fileData);
  424. $saved = $file->compound()->create($compoundData);
  425. }
  426. }elseif(($request->jenis == 'Pelbagai_KT') || ($request->jenis == 'Pelbagai_JPB') || ($request->jenis == 'Pelbagai_PA') || ($request->jenis == 'Pelbagai_LESEN')){
  427. $kpd = $request->kpd;
  428. $compound = Compound::where('jenis', $request->jenis)->where('kpd', $kpd)->first();
  429. info($compound);
  430. if(!empty($compound)) {
  431. $saved = '';
  432. if($compound->modul != '03')
  433. {
  434. if($request->jenis == 'Pelbagai_KT'){
  435. $compound->jenis = $request->jenis;
  436. $compound->nama = $request->namaP;
  437. $compound->identity = $request->noIc;
  438. $compound->nama_syarikat = $request->namaS;
  439. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  440. $compound->alamat = $request->alamat;
  441. $compound->no_plate = $request->no_plate;
  442. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  443. // $compound->nama_kawasan = $request->namaKawasan;
  444. // $compound->nama_taman = $request->namaTaman;
  445. // $compound->nama_jalan = $request->namaJalan;
  446. $compound->catatan = $request->catatan;
  447. $compound->latlong = $request->Latlong;
  448. // $compound->akta = $faulty->deed_law_id;
  449. // $compound->seksyen_kesalahan = $faulty->_id;
  450. // $compound->jumlah_asal_kompaun = $faulty->amount;
  451. $compound->dikeluarkan_ = $staff->_id;
  452. $compound->status = 'Belum Bayar';
  453. $compound->modul = '03';
  454. $compound->no_telefon = $request->tel;
  455. $compound->no_akaun_lesen = $request->lesen;
  456. $compound->cpn_created = Carbon::now()->toDateTimeString();
  457. }elseif($request->jenis == 'Pelbagai_JPB'){
  458. $compound->jenis = $request->jenis;
  459. $compound->nama = $request->namaP;
  460. $compound->identity = $request->noIc;
  461. $compound->nama_syarikat = $request->namaS;
  462. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  463. $compound->alamat = $request->alamat;
  464. $compound->no_plate = $request->no_plate;
  465. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  466. // $compound->nama_kawasan => $request->namaKawasan;
  467. // $compound->nama_taman => $request->namaTaman;
  468. // $compound->nama_jalan => $request->namaJalan;
  469. $compound->catatan = $request->catatan;
  470. $compound->latlong = $request->Latlong;
  471. // $compound->akta => $faulty->deed_law_id;
  472. // $compound->seksyen_kesalahan => $faulty->_id;
  473. // $compound->jumlah_asal_kompaun => $faulty->amount;
  474. $compound->dikeluarkan_ = $staff->_id;
  475. $compound->status = 'Belum Bayar';
  476. $compound->modul = '03';
  477. $compound->no_telefon = $request->tel;
  478. $compound->no_akaun_lesen = $request->lesen;
  479. $compound->cpn_created = Carbon::now()->toDateTimeString();
  480. }elseif($request->jenis == 'Pelbagai_PA'){
  481. $compound->jenis = $request->jenis;
  482. $compound->nama = $request->namaP;
  483. $compound->identity = $request->noIc;
  484. $compound->nama_syarikat = $request->namaS;
  485. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  486. $compound->alamat = $request->alamat;
  487. // $compound->no_plate = $request->no_plate;
  488. // $compound->no_cukai_jalan = $request->no_cukai_jalan;
  489. // $compound->nama_kawasan = $request->namaKawasan;
  490. // $compound->nama_taman = $request->namaTaman;
  491. // $compound->nama_jalan = $request->namaJalan;
  492. $compound->catatan = $request->catatan;
  493. $compound->latlong = $request->Latlong;
  494. // $compound->akta = $faulty->deed_law_id;
  495. // $compound->seksyen_kesalahan = $faulty->_id;
  496. // $compound->jumlah_asal_kompaun = $faulty->amount;
  497. $compound->dikeluarkan_ = $staff->_id;
  498. $compound->status = 'Belum Bayar';
  499. $compound->modul = '03';
  500. $compound->no_telefon = $request->tel;
  501. $compound->no_akaun_lesen = $request->lesen;
  502. $compound->bil_haiwan = $request->lesen;
  503. $compound->cpn_created = Carbon::now()->toDateTimeString();
  504. }elseif($request->jenis == 'Pelbagai_LESEN'){
  505. $compound->jenis = $request->jenis;
  506. $compound->nama = $request->namaP;
  507. $compound->identity = $request->noIc;
  508. $compound->nama_syarikat = $request->namaS;
  509. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  510. $compound->alamat = $request->alamat;
  511. $compound->no_plate = $request->no_plate;
  512. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  513. // $compound->nama_kawasan = $request->namaKawasan;
  514. // $compound->nama_taman = $request->namaTaman;
  515. // $compound->nama_jalan = $request->namaJalan;
  516. $compound->catatan = $request->catatan;
  517. $compound->latlong = $request->Latlong;
  518. // $compound->akta = $faulty->deed_law_id;
  519. // $compound->seksyen_kesalahan = $faulty->_id;
  520. // $compound->jumlah_asal_kompaun = $faulty->amount;
  521. $compound->dikeluarkan_ = $staff->_id;
  522. $compound->status = 'Belum Bayar';
  523. $compound->modul = '03';
  524. $compound->no_telefon = $request->tel;
  525. $compound->no_akaun_lesen = $request->lesen;
  526. $compound->cpn_created = Carbon::now()->toDateTimeString();
  527. }
  528. $saved = $compound->save();
  529. }
  530. else
  531. {
  532. return $this->sendResponse('', 'Kompaun ini telah dikeluarkan!');
  533. }
  534. if($saved){
  535. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  536. // if(!empty($compound)){
  537. dispatch(new UpdateCompoundPrice($kpd));
  538. // $tawaran = '';
  539. // if($compound->jumlah_kemaskini_kompaun != ''){
  540. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  541. // }else{
  542. // $tawaran = $compound->jumlah_asal_kompaun;
  543. // }
  544. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  545. array_push($data, array('kpd' => $kpd));
  546. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  547. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  548. // }
  549. }
  550. }
  551. else{
  552. return $this->sendResponse('', 'Kompaun ini tidak dijumpai!');
  553. }
  554. }
  555. }
  556. }
  557. /**
  558. *
  559. * Store a newly created notice
  560. *
  561. **/
  562. public function storeNewNotice(Request $request)
  563. {
  564. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  565. if(empty($staff)){
  566. return $this->sendError('Invalid', 'Staff not existed');
  567. }else {
  568. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  569. if(!empty($faulty)){
  570. $data = array();
  571. $non = '';
  572. $kpd = '';
  573. $no_siri ='';
  574. // $countKPD = $this->compound->withTrashed()->count(); //for parking numbering
  575. // do {
  576. // $kpd = $kpd + 1;
  577. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  578. // $kpd = 'KP'.$countKPD;
  579. // $no_siri = date('yn').'-'.$countKPD;
  580. // $fileData = [
  581. // 'no_siri' => $no_siri,
  582. // ];
  583. if($request->jenis == 'Parkir'){
  584. //for compound numbering
  585. $countKPD = $this->compound->withTrashed()->count();
  586. $kpd = 'KPD'.$countKPD;
  587. $non = 'KPD'.$countKPD;
  588. $no_siri = date('yn').'-'.$countKPD.'-0';
  589. $compoundData = [
  590. 'jenis' => 'Parkir',
  591. 'kpd' => $kpd,
  592. 'non' => $non,
  593. 'nama' => '-',
  594. 'identity' => '-',
  595. 'alamat' => '-',
  596. "no_plate" => strtolower($request->no_plate),
  597. "no_cukai_jalan" => $request->noCukaijalan,
  598. "jenis_kenderaan" => $request->jenisKenderaan,
  599. "model_kenderaan" => $request->modelKenderaan,
  600. "warna_kenderaan" => $request->warnakenderaan,
  601. "nama_kawasan" => $request->namaKawasan,
  602. "nama_taman" => $request->namaTaman,
  603. "nama_jalan" => $request->namaJalan,
  604. "no_parking" => $request->noParking,
  605. "catatan" => $request->catatan,
  606. "lokasi_kejadian" => '-',
  607. 'latlong' => $request->Latlong,
  608. 'jbkod' => $request->jabatan,
  609. 'akta' => $faulty->deed_law_id,
  610. 'seksyen_kesalahan' => $faulty->_id,
  611. 'jumlah_asal_kompaun' => $faulty->amount,
  612. 'jumlah_kemaskini_kompaun' => '-',
  613. 'dikeluarkan' => $staff->_id,
  614. "status" => 'Belum Bayar',
  615. "amount_payment" => '-',
  616. "receipt" => '-',
  617. "modul" => $request->modul,
  618. "penguatkuasa" => '-',
  619. "notis_created" => Carbon::now()->toDateTimeString(),
  620. ];
  621. }elseif($request->jenis == 'Pelbagai_KT'){
  622. $kpd = $this->generateCompoundNumber($request->jenis, 'KT');
  623. $non = 'NKG'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  624. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  625. $compoundData = [
  626. 'jenis' => $request->jenis,
  627. 'kpd' => $kpd,
  628. 'non' => $non,
  629. 'nama' => $request->namaP,
  630. 'identity' => $request->noIc,
  631. 'nama_syarikat' => $request->namaS,
  632. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  633. 'alamat' => $request->alamat,
  634. "no_plate" => $request->no_plate,
  635. "no_cukai_jalan" => $request->no_cukai_jalan,
  636. "nama_kawasan" => $request->namaKawasan,
  637. "nama_taman" => $request->namaTaman,
  638. "nama_jalan" => $request->namaJalan,
  639. "catatan" => $request->catatan,
  640. "lokasi_kejadian" => '-',
  641. 'latlong' => $request->Latlong,
  642. 'jbkod' => $request->jabatan,
  643. 'akta' => $faulty->deed_law_id,
  644. 'seksyen_kesalahan' => $faulty->_id,
  645. 'jumlah_asal_kompaun' => $faulty->amount,
  646. 'jumlah_kemaskini_kompaun' => '-',
  647. 'dikeluarkan' => $staff->_id,
  648. "status" => 'Belum Bayar',
  649. "amount_payment" => '-',
  650. "receipt" => '-',
  651. "modul" => $request->modul,
  652. "penguatkuasa" => '-',
  653. "no_telefon" => $request->tel,
  654. "no_akaun_lesen" => $request->lesen,
  655. "maklumat_tambahan" => '-',
  656. "tindakan" => $request->tindakan,
  657. "tempoh" => $request->tempoh,
  658. "notis_created" => Carbon::now()->toDateTimeString(),
  659. ];
  660. }elseif($request->jenis == 'Pelbagai_JPB'){
  661. $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  662. $non = 'NMH'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  663. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  664. $compoundData = [
  665. 'jenis' => $request->jenis,
  666. 'kpd' => $kpd,
  667. 'non' => $non,
  668. 'nama' => $request->namaP,
  669. 'identity' => $request->noIc,
  670. 'nama_syarikat' => $request->namaS,
  671. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  672. 'alamat' => $request->alamat,
  673. "no_plate" => $request->no_plate,
  674. "no_cukai_jalan" => $request->no_cukai_jalan,
  675. "nama_kawasan" => $request->namaKawasan,
  676. "nama_taman" => $request->namaTaman,
  677. "nama_jalan" => $request->namaJalan,
  678. "catatan" => $request->catatan,
  679. "lokasi_kejadian" => '-',
  680. 'latlong' => $request->Latlong,
  681. 'jbkod' => $request->jabatan,
  682. 'akta' => $faulty->deed_law_id,
  683. 'seksyen_kesalahan' => $faulty->_id,
  684. 'jumlah_asal_kompaun' => $faulty->amount,
  685. 'jumlah_kemaskini_kompaun' => '-',
  686. 'dikeluarkan' => $staff->_id,
  687. "status" => 'Belum Bayar',
  688. "amount_payment" => '-',
  689. "receipt" => '-',
  690. "modul" => $request->modul,
  691. "penguatkuasa" => '-',
  692. "no_telefon" => $request->tel,
  693. "no_akaun_lesen" => $request->lesen,
  694. "maklumat_tambahan" => '-',
  695. "tindakan" => $request->tindakan,
  696. "tempoh" => $request->tempoh,
  697. "notis_created" => Carbon::now()->toDateTimeString(),
  698. ];
  699. }
  700. elseif($request->jenis == 'Pelbagai_LESEN'){
  701. //HN bcs other N stands for notice. compound number no need front N
  702. $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  703. $non = 'NHN'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  704. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-3';
  705. $compoundData = [
  706. 'jenis' => $request->jenis,
  707. 'kpd' => $kpd,
  708. 'non' => $non,
  709. 'nama' => $request->namaP,
  710. 'identity' => $request->noIc,
  711. 'nama_syarikat' => $request->namaS,
  712. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  713. 'alamat' => $request->alamat,
  714. "no_plate" => $request->no_plate,
  715. "no_cukai_jalan" => $request->no_cukai_jalan,
  716. "nama_kawasan" => $request->namaKawasan,
  717. "nama_taman" => $request->namaTaman,
  718. "nama_jalan" => $request->namaJalan,
  719. "catatan" => $request->catatan,
  720. "lokasi_kejadian" => '-',
  721. 'latlong' => $request->Latlong,
  722. 'jbkod' => $request->jabatan,
  723. 'akta' => $faulty->deed_law_id,
  724. 'seksyen_kesalahan' => $faulty->_id,
  725. 'jumlah_asal_kompaun' => $faulty->amount,
  726. 'jumlah_kemaskini_kompaun' => '-',
  727. 'dikeluarkan' => $staff->_id,
  728. "status" => 'Belum Bayar',
  729. "amount_payment" => '-',
  730. "receipt" => '-',
  731. "modul" => $request->modul,
  732. "penguatkuasa" => '-',
  733. "no_telefon" => $request->tel,
  734. "no_akaun_lesen" => $request->lesen,
  735. "maklumat_tambahan" => '-',
  736. "notis_created" => Carbon::now()->toDateTimeString(),
  737. ];
  738. }
  739. elseif($request->jenis == 'Pelbagai_PA'){
  740. $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  741. $non = 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  742. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-4';
  743. $compoundData = [
  744. 'jenis' => $request->jenis,
  745. 'kpd' => $kpd,
  746. 'non' => $non,
  747. 'nama' => $request->namaP,
  748. 'identity' => $request->noIc,
  749. 'nama_syarikat' => $request->namaS,
  750. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  751. 'alamat' => $request->alamat,
  752. "no_plate" => $request->no_plate,
  753. "no_cukai_jalan" => $request->no_cukai_jalan,
  754. "nama_kawasan" => $request->namaKawasan,
  755. "nama_taman" => $request->namaTaman,
  756. "nama_jalan" => $request->namaJalan,
  757. "catatan" => $request->catatan,
  758. "lokasi_kejadian" => '-',
  759. 'latlong' => $request->Latlong,
  760. 'jbkod' => $request->jabatan,
  761. 'akta' => $faulty->deed_law_id,
  762. 'seksyen_kesalahan' => $faulty->_id,
  763. 'jumlah_asal_kompaun' => $faulty->amount,
  764. 'jumlah_kemaskini_kompaun' => '-',
  765. 'dikeluarkan' => $staff->_id,
  766. "status" => 'Belum Bayar',
  767. "amount_payment" => '-',
  768. "receipt" => '-',
  769. "modul" => $request->modul,
  770. "penguatkuasa" => '-',
  771. "no_telefon" => $request->tel,
  772. "no_akaun_lesen" => $request->lesen,
  773. "maklumat_tambahan" => '-',
  774. "bil_haiwan" => $request->bil_haiwan,
  775. "notis_created" => Carbon::now()->toDateTimeString(),
  776. ];
  777. }
  778. $fileData = [
  779. 'no_siri' => $no_siri,
  780. ];
  781. $file = ConfidentialFile::create($fileData);
  782. $saved = $file->compound()->create($compoundData);
  783. if($saved){
  784. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  785. // if(!empty($compound)){
  786. dispatch(new UpdateCompoundPrice($kpd));
  787. // $tawaran = '';
  788. // if($compound->jumlah_kemaskini_kompaun != ''){
  789. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  790. // }else{
  791. // $tawaran = $compound->jumlah_asal_kompaun;
  792. // }
  793. $this->dispatch(new StoreNotice($request->all(), $non, $staff->_id, $no_siri));
  794. //mobile already accept 'kpd' string, so no need to change string name to 'notis'.
  795. array_push($data, array(
  796. 'kpd' => $kpd,
  797. 'non' => $non
  798. ));
  799. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  800. // }
  801. }
  802. }
  803. }
  804. }
  805. /**
  806. * Store a newly created compound (parkir, KT, JPB).
  807. *
  808. * @param \Illuminate\Http\Request $request
  809. * @return \Illuminate\Http\Response
  810. */
  811. public function storeNewCompound(Request $request)
  812. {
  813. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  814. if(empty($staff)){
  815. return $this->sendError('Invalid', 'Staff not existed');
  816. }else {
  817. $data = array();
  818. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  819. if(!empty($faulty)){
  820. $kpd = '';
  821. $no_siri ='';
  822. // $countKPD = $this->compound->withTrashed()->count();
  823. // do {
  824. // $countKPD = $countKPD + 1;
  825. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  826. // $kpd = $countKPD;
  827. // $no_siri = date('yn').'-'.$countKPD;
  828. // $fileData = [
  829. // 'no_siri' => $no_siri,
  830. // ];
  831. if($request->jenis == 'Parkir')
  832. {
  833. //for compound numbering
  834. $countKPD = $this->compound->withTrashed()->count();
  835. $kpd = 'KPD'.$countKPD;
  836. $no_siri = date('yn').'-'.$countKPD.'-0';
  837. //only for compound parkir
  838. $compoundData = [
  839. 'jenis' => 'Parkir',
  840. 'kpd' => $kpd,
  841. 'nama' => '-',
  842. 'identity' => '-',
  843. 'alamat' => '-',
  844. "no_plate" => strtolower($request->no_plate),
  845. "no_cukai_jalan" => $request->noCukaijalan,
  846. "jenis_kenderaan" => $request->jenisKenderaan,
  847. "model_kenderaan" => $request->modelKenderaan,
  848. "warna_kenderaan" => $request->warnakenderaan,
  849. "nama_kawasan" => $request->namaKawasan,
  850. "nama_taman" => $request->namaTaman,
  851. "nama_jalan" => $request->namaJalan,
  852. "no_parking" => $request->noParking,
  853. "catatan" => $request->catatan,
  854. "lokasi_kejadian" => '-',
  855. 'latlong' => $request->Latlong,
  856. 'jbkod' => $request->jabatan,
  857. 'akta' => $faulty->deed_law_id,
  858. 'seksyen_kesalahan' => $faulty->_id,
  859. 'jumlah_asal_kompaun' => $faulty->amount,
  860. 'jumlah_kemaskini_kompaun' => '-',
  861. 'dikeluarkan' => $staff->_id,
  862. "status" => 'Belum Bayar',
  863. "amount_payment" => '-',
  864. "receipt" => '-',
  865. "modul" => '03',
  866. "penguatkuasa" => '-',
  867. "cpn_created" => Carbon::now()->toDateTimeString(),
  868. ];
  869. }
  870. if ($request->jenis == 'Pelbagai_KT') {
  871. $kpd = $this->generateCompoundNumber($request->jenis, 'KT');
  872. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  873. $compoundData = [
  874. 'jenis' => $request->jenis,
  875. 'kpd' => $kpd,
  876. 'nama' => $request->namaP,
  877. 'identity' => $request->noIc,
  878. 'nama_syarikat' => $request->namaS,
  879. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  880. 'alamat' => $request->alamat,
  881. "no_plate" => $request->no_plate,
  882. "no_cukai_jalan" => $request->no_cukai_jalan,
  883. "nama_kawasan" => $request->namaKawasan,
  884. "nama_taman" => $request->namaTaman,
  885. "nama_jalan" => $request->namaJalan,
  886. "catatan" => $request->catatan,
  887. "lokasi_kejadian" => '-',
  888. 'latlong' => $request->Latlong,
  889. 'jbkod' => $request->jabatan,
  890. 'akta' => $faulty->deed_law_id,
  891. 'seksyen_kesalahan' => $faulty->_id,
  892. 'jumlah_asal_kompaun' => $faulty->amount,
  893. 'jumlah_kemaskini_kompaun' => '-',
  894. 'dikeluarkan' => $staff->_id,
  895. "status" => 'Belum Bayar',
  896. "amount_payment" => '-',
  897. "receipt" => '-',
  898. "modul" => $request->modul,
  899. "penguatkuasa" => '-',
  900. "no_telefon" => $request->tel,
  901. "no_akaun_lesen" => $request->lesen,
  902. "maklumat_tambahan" => '-',
  903. "tindakan" => '-',
  904. "tempoh" => '-',
  905. "cpn_created" => Carbon::now()->toDateTimeString(),
  906. ];
  907. }
  908. elseif ($request->jenis == 'Pelbagai_JPB') {
  909. $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  910. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  911. $compoundData = [
  912. 'jenis' => $request->jenis,
  913. 'kpd' => $kpd,
  914. 'nama' => $request->namaP,
  915. 'identity' => $request->noIc,
  916. 'nama_syarikat' => $request->namaS,
  917. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  918. 'alamat' => $request->alamat,
  919. "no_plate" => $request->no_plate,
  920. "no_cukai_jalan" => $request->no_cukai_jalan,
  921. "nama_kawasan" => $request->namaKawasan,
  922. "nama_taman" => $request->namaTaman,
  923. "nama_jalan" => $request->namaJalan,
  924. "catatan" => $request->catatan,
  925. "lokasi_kejadian" => '-',
  926. 'latlong' => $request->Latlong,
  927. 'jbkod' => $request->jabatan,
  928. 'akta' => $faulty->deed_law_id,
  929. 'seksyen_kesalahan' => $faulty->_id,
  930. 'jumlah_asal_kompaun' => $faulty->amount,
  931. 'jumlah_kemaskini_kompaun' => '-',
  932. 'dikeluarkan' => $staff->_id,
  933. "status" => 'Belum Bayar',
  934. "amount_payment" => '-',
  935. "receipt" => '-',
  936. "modul" => $request->modul,
  937. "penguatkuasa" => '-',
  938. "no_telefon" => $request->tel,
  939. "no_akaun_lesen" => $request->lesen,
  940. "maklumat_tambahan" => '-',
  941. "tindakan" => '-',
  942. "tempoh" => '-',
  943. "cpn_created" => Carbon::now()->toDateTimeString(),
  944. ];
  945. }
  946. elseif ($request->jenis == 'Pelbagai_LESEN') {
  947. //HN bcs other N stands for notice. compound number no need front N
  948. $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  949. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-3';
  950. $compoundData = [
  951. 'jenis' => $request->jenis,
  952. 'kpd' => $kpd,
  953. 'nama' => $request->namaP,
  954. 'identity' => $request->noIc,
  955. 'nama_syarikat' => $request->namaS,
  956. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  957. 'alamat' => $request->alamat,
  958. "no_plate" => $request->no_plate,
  959. "no_cukai_jalan" => $request->no_cukai_jalan,
  960. "nama_kawasan" => $request->namaKawasan,
  961. "nama_taman" => $request->namaTaman,
  962. "nama_jalan" => $request->namaJalan,
  963. "catatan" => $request->catatan,
  964. "lokasi_kejadian" => '-',
  965. 'latlong' => $request->Latlong,
  966. 'jbkod' => $request->jabatan,
  967. 'akta' => $faulty->deed_law_id,
  968. 'seksyen_kesalahan' => $faulty->_id,
  969. 'jumlah_asal_kompaun' => $faulty->amount,
  970. 'jumlah_kemaskini_kompaun' => '-',
  971. 'dikeluarkan' => $staff->_id,
  972. "status" => 'Belum Bayar',
  973. "amount_payment" => '-',
  974. "receipt" => '-',
  975. "modul" => $request->modul,
  976. "penguatkuasa" => '-',
  977. "no_telefon" => $request->tel,
  978. "no_akaun_lesen" => $request->lesen,
  979. "maklumat_tambahan" => '-',
  980. "cpn_created" => Carbon::now()->toDateTimeString(),
  981. ];
  982. }
  983. else if($request->jenis == 'Pelbagai_PA'){
  984. $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  985. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-4';
  986. $compoundData = [
  987. 'jenis' => $request->jenis,
  988. 'kpd' => $kpd,
  989. 'nama' => $request->namaP,
  990. 'identity' => $request->noIc,
  991. 'nama_syarikat' => $request->namaS,
  992. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  993. 'alamat' => $request->alamat,
  994. "no_plate" => $request->no_plate,
  995. "no_cukai_jalan" => $request->no_cukai_jalan,
  996. "nama_kawasan" => $request->namaKawasan,
  997. "nama_taman" => $request->namaTaman,
  998. "nama_jalan" => $request->namaJalan,
  999. "catatan" => $request->catatan,
  1000. "lokasi_kejadian" => '-',
  1001. 'latlong' => $request->Latlong,
  1002. 'jbkod' => $request->jabatan,
  1003. 'akta' => $faulty->deed_law_id,
  1004. 'seksyen_kesalahan' => $faulty->_id,
  1005. 'jumlah_asal_kompaun' => $faulty->amount,
  1006. 'jumlah_kemaskini_kompaun' => '-',
  1007. 'dikeluarkan' => $staff->_id,
  1008. "status" => 'Belum Bayar',
  1009. "amount_payment" => '-',
  1010. "receipt" => '-',
  1011. "modul" => $request->modul,
  1012. "penguatkuasa" => '-',
  1013. "no_telefon" => $request->tel,
  1014. "no_akaun_lesen" => $request->lesen,
  1015. "maklumat_tambahan" => '-',
  1016. "bil_haiwan" => $request->bil_haiwan,
  1017. "cpn_created" => Carbon::now()->toDateTimeString(),
  1018. ];
  1019. }
  1020. $fileData = [
  1021. 'no_siri' => $no_siri,
  1022. ];
  1023. $file = ConfidentialFile::create($fileData);
  1024. $saved = $file->compound()->create($compoundData);
  1025. if($saved){
  1026. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  1027. // if(!empty($compound)){
  1028. dispatch(new UpdateCompoundPrice($kpd));
  1029. // $tawaran = '';
  1030. // if($compound->jumlah_kemaskini_kompaun != ''){
  1031. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  1032. // }else{
  1033. // $tawaran = $compound->jumlah_asal_kompaun;
  1034. // }
  1035. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  1036. array_push($data, array('kpd' => $kpd));
  1037. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  1038. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  1039. }
  1040. return $this->sendError('', 'Tidak berjaya simpan rekod kompaun!');
  1041. }
  1042. return $this->sendResponse('Tidak Berjaya!', 'Kesalahan tidak dijumpai!');
  1043. }
  1044. }
  1045. /**
  1046. * Display the specified resource.
  1047. *
  1048. * @param int $id
  1049. * @return \Illuminate\Http\Response
  1050. */
  1051. public function show($id)
  1052. {
  1053. //
  1054. }
  1055. /**
  1056. * Show the form for editing the specified resource.
  1057. *
  1058. * @param int $id
  1059. * @return \Illuminate\Http\Response
  1060. */
  1061. public function edit($id)
  1062. {
  1063. //
  1064. }
  1065. /**
  1066. * Update the specified resource in storage.
  1067. *
  1068. * @param \Illuminate\Http\Request $request
  1069. * @param int $id
  1070. * @return \Illuminate\Http\Response
  1071. */
  1072. public function update(Request $request, $id)
  1073. {
  1074. //
  1075. }
  1076. public function updateStatusNoticeViaDashboard(Request $request)
  1077. {
  1078. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1079. $staff = StaffDetail::find($request->current_id);
  1080. if(!empty($compound) && !empty($staff)){
  1081. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1082. if($compound->status != $request->status){
  1083. $compound->status = $request->status;
  1084. $compound->catatan_dari_admin = $request->remark;
  1085. $compound->update_by = $request->current_id;
  1086. $saved = $compound->save();
  1087. if($saved){
  1088. $gDate = $compound->created_at->format('F Y');
  1089. $historyData = [
  1090. 'tarikh_kumpulan' => $gDate,
  1091. ];
  1092. $subHistory = [
  1093. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1094. 'tajuk' => "Status notis ".$compound->kpd. " telah dikemaskini",
  1095. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1096. ];
  1097. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1098. if(!empty($groupByDate)){
  1099. $groupByDate->subhistory()->create($subHistory);
  1100. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1101. }else{
  1102. $history = History::create($historyData);
  1103. $history->subhistory()->create($subHistory);
  1104. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1105. }
  1106. if($request->status == "Berbayar"){
  1107. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1108. }else{
  1109. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1110. }
  1111. }else{
  1112. $response = [
  1113. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1114. ];
  1115. return response()->json($response, 200);
  1116. }
  1117. }else{
  1118. if($request->remark != ''){
  1119. $compound->catatan_dari_admin = $request->remark;
  1120. $compound->update_by = $request->current_id;
  1121. $compound->save();
  1122. $saved = $compound->save();
  1123. if($saved){
  1124. $gDate = $compound->created_at->format('F Y');
  1125. $historyData = [
  1126. 'tarikh_kumpulan' => $gDate,
  1127. ];
  1128. $subHistory = [
  1129. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1130. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1131. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1132. ];
  1133. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1134. if(!empty($groupByDate)){
  1135. $groupByDate->subhistory()->create($subHistory);
  1136. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1137. }else{
  1138. $history = History::create($historyData);
  1139. $history->subhistory()->create($subHistory);
  1140. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1141. }
  1142. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1143. }else{
  1144. $response = [
  1145. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1146. ];
  1147. return response()->json($response, 200);
  1148. }
  1149. }else{
  1150. $response = [
  1151. 'success' => false, 'message' => 'Tiada kemaskini!',
  1152. ];
  1153. return response()->json($response, 200);
  1154. }
  1155. }
  1156. }else{
  1157. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1158. $compound->status = $request->status;
  1159. $compound->catatan_dari_admin = $request->remark;
  1160. // $compound->amount_payment = $request->amount;
  1161. $compound->update_by = $request->current_id;
  1162. $saved = $compound->save();
  1163. if($saved){
  1164. $gDate = $compound->created_at->format('F Y');
  1165. $historyData = [
  1166. 'tarikh_kumpulan' => $gDate,
  1167. ];
  1168. $subHistory = [
  1169. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1170. 'tajuk' => "Status notis telah dikemaskini",
  1171. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1172. ];
  1173. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1174. if(!empty($groupByDate)){
  1175. $groupByDate->subhistory()->create($subHistory);
  1176. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1177. }else{
  1178. $history = History::create($historyData);
  1179. $history->subhistory()->create($subHistory);
  1180. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1181. }
  1182. if($request->status == "Berbayar"){
  1183. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1184. }else{
  1185. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1186. }
  1187. }else{
  1188. $response = [
  1189. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1190. ];
  1191. return response()->json($response, 200);
  1192. }
  1193. }else{
  1194. if($request->remark != ''){
  1195. $compound->catatan_dari_admin = $request->remark;
  1196. $compound->update_by = $request->current_id;
  1197. $compound->save();
  1198. $saved = $compound->save();
  1199. if($saved){
  1200. $gDate = $compound->created_at->format('F Y');
  1201. $historyData = [
  1202. 'tarikh_kumpulan' => $gDate,
  1203. ];
  1204. $subHistory = [
  1205. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1206. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1207. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1208. ];
  1209. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1210. if(!empty($groupByDate)){
  1211. $groupByDate->subhistory()->create($subHistory);
  1212. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1213. }else{
  1214. $history = History::create($historyData);
  1215. $history->subhistory()->create($subHistory);
  1216. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1217. }
  1218. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1219. }else{
  1220. $response = [
  1221. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1222. ];
  1223. return response()->json($response, 200);
  1224. }
  1225. }else{
  1226. $response = [
  1227. 'success' => false, 'message' => 'Tiada kemaskini!',
  1228. ];
  1229. return response()->json($response, 200);
  1230. }
  1231. }
  1232. }
  1233. }else{
  1234. $response = [
  1235. 'success' => false,
  1236. 'message' => 'Notis ini tidak dijumpai / staff tidak ditemui',
  1237. ];
  1238. return response()->json($response, 200);
  1239. }
  1240. }
  1241. public function updateStatusPaymentViaDashboard(Request $request)
  1242. {
  1243. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1244. $staff = StaffDetail::find($request->current_id);
  1245. if(!empty($compound) && !empty($staff)){
  1246. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1247. if($compound->status != $request->status){
  1248. $compound->status = $request->status;
  1249. $compound->catatan_dari_admin = $request->remark;
  1250. $compound->amount_payment = $request->amount;
  1251. $compound->update_by = $request->current_id;
  1252. $saved = $compound->save();
  1253. if($saved){
  1254. $gDate = $compound->created_at->format('F Y');
  1255. $historyData = [
  1256. 'tarikh_kumpulan' => $gDate,
  1257. ];
  1258. $subHistory = [
  1259. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1260. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1261. '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>",
  1262. ];
  1263. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1264. if(!empty($groupByDate)){
  1265. $groupByDate->subhistory()->create($subHistory);
  1266. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1267. }else{
  1268. $history = History::create($historyData);
  1269. $history->subhistory()->create($subHistory);
  1270. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1271. }
  1272. if($request->status == "Berbayar"){
  1273. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1274. }else{
  1275. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1276. }
  1277. }else{
  1278. $response = [
  1279. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1280. ];
  1281. return response()->json($response, 200);
  1282. }
  1283. }else{
  1284. if($request->remark != ''){
  1285. $compound->catatan_dari_admin = $request->remark;
  1286. $compound->update_by = $request->current_id;
  1287. $compound->save();
  1288. $saved = $compound->save();
  1289. if($saved){
  1290. $gDate = $compound->created_at->format('F Y');
  1291. $historyData = [
  1292. 'tarikh_kumpulan' => $gDate,
  1293. ];
  1294. $subHistory = [
  1295. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1296. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1297. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1298. ];
  1299. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1300. if(!empty($groupByDate)){
  1301. $groupByDate->subhistory()->create($subHistory);
  1302. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1303. }else{
  1304. $history = History::create($historyData);
  1305. $history->subhistory()->create($subHistory);
  1306. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1307. }
  1308. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1309. }else{
  1310. $response = [
  1311. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1312. ];
  1313. return response()->json($response, 200);
  1314. }
  1315. }else{
  1316. $response = [
  1317. 'success' => false, 'message' => 'Tiada kemaskini!',
  1318. ];
  1319. return response()->json($response, 200);
  1320. }
  1321. }
  1322. }else{
  1323. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1324. $compound->status = $request->status;
  1325. $compound->catatan_dari_admin = $request->remark;
  1326. $compound->amount_payment = $request->amount;
  1327. $compound->update_by = $request->current_id;
  1328. $saved = $compound->save();
  1329. if($saved){
  1330. $gDate = $compound->created_at->format('F Y');
  1331. $historyData = [
  1332. 'tarikh_kumpulan' => $gDate,
  1333. ];
  1334. $subHistory = [
  1335. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1336. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1337. '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>",
  1338. ];
  1339. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1340. if(!empty($groupByDate)){
  1341. $groupByDate->subhistory()->create($subHistory);
  1342. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1343. }else{
  1344. $history = History::create($historyData);
  1345. $history->subhistory()->create($subHistory);
  1346. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1347. }
  1348. if($request->status == "Berbayar"){
  1349. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1350. }else{
  1351. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1352. }
  1353. }else{
  1354. $response = [
  1355. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1356. ];
  1357. return response()->json($response, 200);
  1358. }
  1359. }else{
  1360. if($request->remark != ''){
  1361. $compound->catatan_dari_admin = $request->remark;
  1362. $compound->update_by = $request->current_id;
  1363. $compound->save();
  1364. $saved = $compound->save();
  1365. if($saved){
  1366. $gDate = $compound->created_at->format('F Y');
  1367. $historyData = [
  1368. 'tarikh_kumpulan' => $gDate,
  1369. ];
  1370. $subHistory = [
  1371. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1372. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1373. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1374. ];
  1375. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1376. if(!empty($groupByDate)){
  1377. $groupByDate->subhistory()->create($subHistory);
  1378. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1379. }else{
  1380. $history = History::create($historyData);
  1381. $history->subhistory()->create($subHistory);
  1382. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1383. }
  1384. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1385. }else{
  1386. $response = [
  1387. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1388. ];
  1389. return response()->json($response, 200);
  1390. }
  1391. }else{
  1392. $response = [
  1393. 'success' => false, 'message' => 'Tiada kemaskini!',
  1394. ];
  1395. return response()->json($response, 200);
  1396. }
  1397. }
  1398. }
  1399. }else{
  1400. $response = [
  1401. 'success' => false,
  1402. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  1403. ];
  1404. return response()->json($response, 200);
  1405. }
  1406. }
  1407. /**
  1408. * Remove the specified resource from storage.
  1409. *
  1410. * @param int $id
  1411. * @return \Illuminate\Http\Response
  1412. */
  1413. public function destroy($id)
  1414. {
  1415. //
  1416. }
  1417. }