Dashboard sipadu mbip
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

CompoundResourceController.php 69KB

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