Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompoundResourceController.php 69KB

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