Dashboard sipadu mbip
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CompoundResourceController.php 69KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  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. "created_c" => Carbon::now()->toDateTimeString(),
  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()->toDateTimeString();
  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()->toDateTimeString();
  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. // dd(Carbon::now()->addDays(5)->toISOString());
  552. $data = array();
  553. $non = '';
  554. // $kpd = '';
  555. $no_siri ='';
  556. $noticeData = [];
  557. if($request->jenis == 'Parkir'){
  558. //for compound numbering
  559. // $countKPD = $this->compound->withTrashed()->count();
  560. // $kpd = 'KPD'.$countKPD;
  561. // $non = 'KPD'.$countKPD;
  562. // $no_siri = date('yn').'-'.$countKPD.'-0';
  563. // $compoundData = [
  564. // 'jenis' => 'Parkir',
  565. // 'kpd' => $kpd,
  566. // 'non' => $non,
  567. // 'nama' => '-',
  568. // 'identity' => '-',
  569. // 'alamat' => '-',
  570. // "no_plate" => strtolower($request->no_plate),
  571. // "no_cukai_jalan" => $request->noCukaijalan,
  572. // "jenis_kenderaan" => $request->jenisKenderaan,
  573. // "model_kenderaan" => $request->modelKenderaan,
  574. // "warna_kenderaan" => $request->warnakenderaan,
  575. // "nama_kawasan" => $request->namaKawasan,
  576. // "nama_taman" => $request->namaTaman,
  577. // "nama_jalan" => $request->namaJalan,
  578. // "no_parking" => $request->noParking,
  579. // "catatan" => $request->catatan,
  580. // "lokasi_kejadian" => '-',
  581. // 'latlong' => $request->Latlong,
  582. // 'jbkod' => $request->jabatan,
  583. // 'akta' => $faulty->deed_law_id,
  584. // 'seksyen_kesalahan' => $faulty->_id,
  585. // 'jumlah_asal_kompaun' => $faulty->amount,
  586. // 'jumlah_kemaskini_kompaun' => '-',
  587. // 'dikeluarkan' => $staff->_id,
  588. // "status" => 'Belum Bayar',
  589. // "amount_payment" => '-',
  590. // "receipt" => '-',
  591. // "modul" => $request->modul,
  592. // "penguatkuasa" => '-',
  593. // "notis_created" => Carbon::now()->toDateTimeString(),
  594. // ];
  595. }elseif($request->jenis == 'Notis_NKG'){
  596. // $kpd = $this->generateNumber($request->jenis, 'KT', '02');
  597. // $non = 'NKG'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  598. $non = $this->generateNumber($request->jenis, 'NKG', '02');
  599. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-1';
  600. $noticeData = [
  601. 'jenis' => 'Pelbagai_KT',
  602. 'jenis_n' => $request->jenis,
  603. 'kpd' => '-',
  604. 'non' => $non,
  605. 'nama' => $request->namaP,
  606. 'identity' => $request->noIc,
  607. 'nama_syarikat' => $request->namaS,
  608. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  609. 'alamat' => $request->alamat,
  610. "nama_kawasan" => $request->namaKawasan,
  611. "nama_taman" => $request->namaTaman,
  612. "nama_jalan" => $request->namaJalan,
  613. "catatan" => $request->butiran_kesalahan,
  614. "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
  615. 'latlong' => $request->Latlong,
  616. 'jbkod' => $request->jabatan,
  617. 'akta_n' => $faulty->deed_law_id,
  618. 'seksyen_kesalahan_n' => $faulty->_id,
  619. 'dikeluarkan_n' => $staff->_id,
  620. "status" => 'Belum Bayar',
  621. "modul" => $request->modul,
  622. "penguatkuasa" => '-',
  623. "no_akaun_lesen" => $request->lesen,
  624. // "maklumat_tambahan" => $request->butiran_kesalahan,
  625. "tindakan" => $request->tindakan,
  626. "tempoh" => $request->tempoh,
  627. // "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh)->toiso(),
  628. "created_n" => Carbon::now()->toDateTimeString(),
  629. ];
  630. }elseif($request->jenis == 'Notis_NMH'){
  631. // $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  632. // $non = 'NMH'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  633. $non = $this->generateNumber($request->jenis, 'NMH', '02');
  634. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-2';
  635. $noticeData = [
  636. 'jenis' => 'Pelbagai_JPB',
  637. 'jenis_n' => $request->jenis,
  638. 'kpd' => '-',
  639. 'non' => $non,
  640. 'nama' => $request->namaP,
  641. 'identity' => $request->noIc,
  642. 'nama_syarikat' => $request->namaS,
  643. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  644. 'alamat' => $request->alamat,
  645. "nama_kawasan" => $request->namaKawasan,
  646. "nama_taman" => $request->namaTaman,
  647. "nama_jalan" => $request->namaJalan,
  648. "catatan" => $request->butiran_kesalahan,
  649. "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
  650. 'latlong' => $request->Latlong,
  651. 'jbkod' => $request->jabatan,
  652. 'akta_n' => $faulty->deed_law_id,
  653. 'seksyen_kesalahan_n' => $faulty->_id,
  654. 'dikeluarkan_n' => $staff->_id,
  655. "status" => 'Belum Bayar',
  656. "modul" => $request->modul,
  657. "penguatkuasa" => '-',
  658. "no_akaun_lesen" => $request->lesen,
  659. // "maklumat_tambahan" => $request->butiran_kesalahan,
  660. "tindakan" => $request->tinadkan,
  661. "tempoh" => $request->tempoh,
  662. // "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh)->toISOString(),
  663. "created_n" => Carbon::now()->toDateTimeString(),
  664. ];
  665. }
  666. elseif($request->jenis == 'Notis_NHN'){
  667. //HN bcs other N stands for notice. compound number no need front N
  668. // $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  669. // $non = 'NHN'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  670. $non = $this->generateNumber($request->jenis, 'NHN', '02' );
  671. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-3';
  672. $noticeData = [
  673. 'jenis' => 'Pelbagai_KT',
  674. 'jenis_n' => $request->jenis,
  675. 'kpd' => '-',
  676. 'non' => $non,
  677. 'nama' => $request->namaP,
  678. 'identity' => $request->noIc,
  679. 'nama_syarikat' => $request->namaS,
  680. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  681. 'alamat' => $request->alamat,
  682. "nama_kawasan" => $request->namaKawasan,
  683. "nama_taman" => $request->namaTaman,
  684. "nama_jalan" => $request->namaJalan,
  685. "catatan" => $request->butiran_kesalahan,
  686. "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
  687. 'latlong' => $request->Latlong,
  688. 'jbkod' => $request->jabatan,
  689. 'akta_n' => $faulty->deed_law_id,
  690. 'seksyen_kesalahan_n' => $faulty->_id,
  691. 'dikeluarkan_n' => $staff->_id,
  692. "status" => 'Belum Bayar',
  693. "modul" => $request->modul,
  694. "penguatkuasa" => '-',
  695. "no_akaun_lesen" => $request->lesen,
  696. // "maklumat_tambahan" => $request->butiran_kesalahan,
  697. // "tindakan" => $request->tindakan,
  698. "tempoh" => $request->tempoh,
  699. // "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh)->toISOString(),
  700. "created_n" => Carbon::now()->toDateTimeString(),
  701. ];
  702. }
  703. elseif($request->jenis == 'Notis_PA'){
  704. // $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  705. // $non = 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  706. $non = $this->generateNumber($request->jenis, 'PA', '02');
  707. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-4';
  708. $noticeData = [
  709. 'jenis' => 'Pelbagai_KT',
  710. 'jenis_n' => $request->jenis,
  711. 'kpd' => '-',
  712. 'non' => $non,
  713. 'nama' => $request->namaP,
  714. 'identity' => $request->noIc,
  715. 'nama_syarikat' => $request->namaS,
  716. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  717. 'alamat' => $request->alamat,
  718. "nama_kawasan" => $request->namaKawasan,
  719. "nama_taman" => $request->namaTaman,
  720. "nama_jalan" => $request->namaJalan,
  721. "catatan" => $request->butiran_kesalahan,
  722. "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
  723. 'latlong' => $request->Latlong,
  724. 'jbkod' => $request->jabatan,
  725. 'akta_n' => $faulty->deed_law_id,
  726. 'seksyen_kesalahan_n' => $faulty->_id,
  727. 'dikeluarkan_n' => $staff->_id,
  728. "status" => 'Belum Bayar',
  729. "modul" => $request->modul,
  730. "penguatkuasa" => '-',
  731. "no_akaun_lesen" => $request->lesen,
  732. // "maklumat_tambahan" => $request->butiran_kesalahan,
  733. "tindakan" => $request->tindakan,
  734. "tempoh" => $request->tempoh,
  735. // "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh)->toISOString(),
  736. "created_n" => Carbon::now()->toDateTimeString(),
  737. "bil_haiwan" => $request->bil_haiwan,
  738. ];
  739. }elseif($request->jenis == 'Notis_NPPM'){
  740. // $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  741. // $non = 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  742. $non = $this->generateNumber($request->jenis, 'NPPM', '02');
  743. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-4';
  744. $noticeData = [
  745. 'jenis' => 'Pelbagai_KT',
  746. 'jenis_n' => $request->jenis,
  747. 'kpd' => '-',
  748. 'non' => $non,
  749. 'nama' => $request->namaP,
  750. 'identity' => $request->noIc,
  751. 'nama_syarikat' => $request->namaS,
  752. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  753. 'alamat' => $request->alamat,
  754. "nama_kawasan" => $request->namaKawasan,
  755. "nama_taman" => $request->namaTaman,
  756. "nama_jalan" => $request->namaJalan,
  757. "catatan" => $request->butiran_kesalahan,
  758. "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
  759. 'latlong' => $request->Latlong,
  760. 'jbkod' => $request->jabatan,
  761. 'akta_n' => $faulty->deed_law_id,
  762. 'seksyen_kesalahan_n' => $faulty->_id,
  763. 'dikeluarkan_n' => $staff->_id,
  764. "status" => 'Belum Bayar',
  765. "modul" => $request->modul,
  766. "penguatkuasa" => '-',
  767. "no_akaun_lesen" => $request->lesen,
  768. // "maklumat_tambahan" => $request->butiran_kesalahan,
  769. "tindakan" => $request->tindakan,
  770. "tempoh" => $request->tempoh,
  771. // "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh)->toISOString(),
  772. "created_n" => Carbon::now()->toDateTimeString(),
  773. ];
  774. }
  775. $fileData = [
  776. 'no_siri' => $no_siri,
  777. ];
  778. $file = ConfidentialFile::create($fileData);
  779. $saved = $file->compound()->create($noticeData);
  780. if($saved){
  781. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  782. // if(!empty($compound)){
  783. // dispatch(new UpdateCompoundPrice($kpd));
  784. // $tawaran = '';
  785. // if($compound->jumlah_kemaskini_kompaun != ''){
  786. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  787. // }else{
  788. // $tawaran = $compound->jumlah_asal_kompaun;
  789. // }
  790. $this->dispatch(new StoreNotice($request->all(), $non, $staff->_id, $no_siri));
  791. //mobile already accept 'kpd' string, so no need to change string name to 'notis'.
  792. array_push($data, array(
  793. 'non' => $non
  794. ));
  795. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  796. // }
  797. }
  798. }
  799. }
  800. }
  801. /**
  802. * Store a newly created compound (parkir, KT, JPB).
  803. *
  804. * @param \Illuminate\Http\Request $request
  805. * @return \Illuminate\Http\Response
  806. */
  807. public function storeNewCompound(Request $request)
  808. {
  809. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  810. if(empty($staff)){
  811. return $this->sendError('Invalid', 'Staff not existed');
  812. }else {
  813. $data = array();
  814. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  815. if(!empty($faulty)){
  816. $kpd = '';
  817. $no_siri ='';
  818. if($request->jenis == 'Parkir')
  819. {
  820. //for compound numbering
  821. $countKPD = $this->compound->where('jenis','Parkir')->withTrashed()->count();
  822. $kpd = 'KPD'.$countKPD;
  823. $no_siri = date('yn').'-'.$countKPD.'-0';
  824. //only for compound parkir
  825. $compoundData = [
  826. 'jenis' => 'Parkir',
  827. 'kpd' => $kpd,
  828. 'nama' => '-',
  829. 'identity' => '-',
  830. 'alamat' => '-',
  831. "no_plate" => strtolower($request->no_plate),
  832. "no_cukai_jalan" => $request->noCukaijalan,
  833. "jenis_kenderaan" => $request->jenisKenderaan,
  834. "model_kenderaan" => $request->modelKenderaan,
  835. "warna_kenderaan" => $request->warnakenderaan,
  836. "nama_kawasan" => $request->namaKawasan,
  837. "nama_taman" => $request->namaTaman,
  838. "nama_jalan" => $request->namaJalan,
  839. "no_parking" => $request->noParking,
  840. "catatan" => $request->catatan,
  841. "lokasi_kejadian" => '-',
  842. 'latlong' => $request->Latlong,
  843. 'jbkod' => $request->jabatan,
  844. 'akta' => $faulty->deed_law_id,
  845. 'seksyen_kesalahan' => $faulty->_id,
  846. 'jumlah_asal_kompaun' => $faulty->amount,
  847. 'jumlah_kemaskini_kompaun' => '-',
  848. 'dikeluarkan' => $staff->_id,
  849. "status" => 'Belum Bayar',
  850. "amount_payment" => '-',
  851. "receipt" => '-',
  852. "modul" => '03',
  853. "penguatkuasa" => '-',
  854. "created_c" => Carbon::now()->toDateTimeString(),
  855. ];
  856. }
  857. if ($request->jenis == 'Pelbagai_KT') {
  858. $kpd = $this->generateNumber($request->jenis, 'KT', '03');
  859. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  860. $compoundData = [
  861. 'jenis' => $request->jenis,
  862. 'kpd' => $kpd,
  863. 'nama' => $request->namaP,
  864. 'identity' => $request->noIc,
  865. 'nama_syarikat' => $request->namaS,
  866. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  867. 'alamat' => $request->alamat,
  868. "lokasi_kejadian" => $request->alamat_tempat_pesalah,
  869. "nama_kawasan" => $request->namaKawasan,
  870. "nama_taman" => $request->namaTaman,
  871. "nama_jalan" => $request->namaJalan,
  872. 'latlong' => $request->Latlong,
  873. 'jbkod' => $request->jabatan,
  874. 'akta' => $faulty->deed_law_id,
  875. 'seksyen_kesalahan' => $faulty->_id,
  876. 'jumlah_asal_kompaun' => $faulty->amount,
  877. 'jumlah_kemaskini_kompaun' => '-',
  878. 'dikeluarkan' => $staff->_id,
  879. "status" => 'Belum Bayar',
  880. "amount_payment" => '-',
  881. "receipt" => '-',
  882. "modul" => $request->modul,
  883. "penguatkuasa" => '-',
  884. "no_akaun_lesen" => $request->lesen,
  885. "created_c" => Carbon::now()->toDateTimeString(),
  886. ];
  887. }
  888. elseif ($request->jenis == 'Pelbagai_JPB') {
  889. $kpd = $this->generateNumber($request->jenis, 'JPB', '03');
  890. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  891. $compoundData = [
  892. 'jenis' => $request->jenis,
  893. 'kpd' => $kpd,
  894. 'nama' => $request->namaP,
  895. 'identity' => $request->noIc,
  896. 'nama_syarikat' => $request->namaS,
  897. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  898. 'alamat' => $request->alamat,
  899. "lokasi_kejadian" => $request->alamat_tempat_pesalah,
  900. "nama_kawasan" => $request->namaKawasan,
  901. "nama_taman" => $request->namaTaman,
  902. "nama_jalan" => $request->namaJalan,
  903. 'latlong' => $request->Latlong,
  904. 'jbkod' => $request->jabatan,
  905. 'akta' => $faulty->deed_law_id,
  906. 'seksyen_kesalahan' => $faulty->_id,
  907. 'jumlah_asal_kompaun' => $faulty->amount,
  908. 'jumlah_kemaskini_kompaun' => '-',
  909. 'dikeluarkan' => $staff->_id,
  910. "status" => 'Belum Bayar',
  911. "amount_payment" => '-',
  912. "receipt" => '-',
  913. "modul" => $request->modul,
  914. "penguatkuasa" => '-',
  915. "no_akaun_lesen" => $request->lesen,
  916. "created_c" => Carbon::now()->toDateTimeString(),
  917. ];
  918. }
  919. $fileData = [
  920. 'no_siri' => $no_siri,
  921. ];
  922. $file = ConfidentialFile::create($fileData);
  923. $saved = $file->compound()->create($compoundData);
  924. if($saved){
  925. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  926. // if(!empty($compound)){
  927. // dispatch(new UpdateCompoundPrice($kpd));
  928. // $tawaran = '';
  929. // if($compound->jumlah_kemaskini_kompaun != ''){
  930. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  931. // }else{
  932. // $tawaran = $compound->jumlah_asal_kompaun;
  933. // }
  934. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  935. array_push($data, array('kpd' => $kpd));
  936. // $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  937. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  938. }
  939. return $this->sendError('', 'Tidak berjaya simpan rekod kompaun!');
  940. }
  941. return $this->sendResponse('Tidak Berjaya!', 'Kesalahan tidak dijumpai!');
  942. }
  943. }
  944. /**
  945. * Display the specified resource.
  946. *
  947. * @param int $id
  948. * @return \Illuminate\Http\Response
  949. */
  950. public function show($id)
  951. {
  952. //
  953. }
  954. /**
  955. * Show the form for editing the specified resource.
  956. *
  957. * @param int $id
  958. * @return \Illuminate\Http\Response
  959. */
  960. public function edit($id)
  961. {
  962. //
  963. }
  964. /**
  965. * Update the specified resource in storage.
  966. *
  967. * @param \Illuminate\Http\Request $request
  968. * @param int $id
  969. * @return \Illuminate\Http\Response
  970. */
  971. public function update(Request $request, $id)
  972. {
  973. //
  974. }
  975. public function updateStatusNoticeViaDashboard(Request $request)
  976. {
  977. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  978. $staff = StaffDetail::find($request->current_id);
  979. if(!empty($compound) && !empty($staff)){
  980. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  981. if($compound->status != $request->status){
  982. $compound->status = $request->status;
  983. $compound->catatan_dari_admin = $request->remark;
  984. $compound->update_by = $request->current_id;
  985. $saved = $compound->save();
  986. if($saved){
  987. $gDate = $compound->created_at->format('F Y');
  988. $historyData = [
  989. 'tarikh_kumpulan' => $gDate,
  990. ];
  991. $subHistory = [
  992. 'no_siri' => $compound->ConfidentialFile->no_siri,
  993. 'tajuk' => "Status notis ".$compound->kpd. " telah dikemaskini",
  994. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  995. ];
  996. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  997. if(!empty($groupByDate)){
  998. $groupByDate->subhistory()->create($subHistory);
  999. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1000. }else{
  1001. $history = History::create($historyData);
  1002. $history->subhistory()->create($subHistory);
  1003. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1004. }
  1005. if($request->status == "Berbayar"){
  1006. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1007. }else{
  1008. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1009. }
  1010. }else{
  1011. $response = [
  1012. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1013. ];
  1014. return response()->json($response, 200);
  1015. }
  1016. }else{
  1017. if($request->remark != ''){
  1018. $compound->catatan_dari_admin = $request->remark;
  1019. $compound->update_by = $request->current_id;
  1020. $compound->save();
  1021. $saved = $compound->save();
  1022. if($saved){
  1023. $gDate = $compound->created_at->format('F Y');
  1024. $historyData = [
  1025. 'tarikh_kumpulan' => $gDate,
  1026. ];
  1027. $subHistory = [
  1028. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1029. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1030. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1031. ];
  1032. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1033. if(!empty($groupByDate)){
  1034. $groupByDate->subhistory()->create($subHistory);
  1035. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1036. }else{
  1037. $history = History::create($historyData);
  1038. $history->subhistory()->create($subHistory);
  1039. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1040. }
  1041. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1042. }else{
  1043. $response = [
  1044. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1045. ];
  1046. return response()->json($response, 200);
  1047. }
  1048. }else{
  1049. $response = [
  1050. 'success' => false, 'message' => 'Tiada kemaskini!',
  1051. ];
  1052. return response()->json($response, 200);
  1053. }
  1054. }
  1055. }else{
  1056. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1057. $compound->status = $request->status;
  1058. $compound->catatan_dari_admin = $request->remark;
  1059. // $compound->amount_payment = $request->amount;
  1060. $compound->update_by = $request->current_id;
  1061. $saved = $compound->save();
  1062. if($saved){
  1063. $gDate = $compound->created_at->format('F Y');
  1064. $historyData = [
  1065. 'tarikh_kumpulan' => $gDate,
  1066. ];
  1067. $subHistory = [
  1068. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1069. 'tajuk' => "Status notis telah dikemaskini",
  1070. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1071. ];
  1072. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1073. if(!empty($groupByDate)){
  1074. $groupByDate->subhistory()->create($subHistory);
  1075. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1076. }else{
  1077. $history = History::create($historyData);
  1078. $history->subhistory()->create($subHistory);
  1079. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1080. }
  1081. if($request->status == "Berbayar"){
  1082. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1083. }else{
  1084. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1085. }
  1086. }else{
  1087. $response = [
  1088. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1089. ];
  1090. return response()->json($response, 200);
  1091. }
  1092. }else{
  1093. if($request->remark != ''){
  1094. $compound->catatan_dari_admin = $request->remark;
  1095. $compound->update_by = $request->current_id;
  1096. $compound->save();
  1097. $saved = $compound->save();
  1098. if($saved){
  1099. $gDate = $compound->created_at->format('F Y');
  1100. $historyData = [
  1101. 'tarikh_kumpulan' => $gDate,
  1102. ];
  1103. $subHistory = [
  1104. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1105. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1106. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1107. ];
  1108. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1109. if(!empty($groupByDate)){
  1110. $groupByDate->subhistory()->create($subHistory);
  1111. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1112. }else{
  1113. $history = History::create($historyData);
  1114. $history->subhistory()->create($subHistory);
  1115. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1116. }
  1117. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1118. }else{
  1119. $response = [
  1120. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1121. ];
  1122. return response()->json($response, 200);
  1123. }
  1124. }else{
  1125. $response = [
  1126. 'success' => false, 'message' => 'Tiada kemaskini!',
  1127. ];
  1128. return response()->json($response, 200);
  1129. }
  1130. }
  1131. }
  1132. }else{
  1133. $response = [
  1134. 'success' => false,
  1135. 'message' => 'Notis ini tidak dijumpai / staff tidak ditemui',
  1136. ];
  1137. return response()->json($response, 200);
  1138. }
  1139. }
  1140. public function updateStatusPaymentViaDashboard(Request $request)
  1141. {
  1142. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1143. $staff = StaffDetail::find($request->current_id);
  1144. if(!empty($compound) && !empty($staff)){
  1145. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1146. if($compound->status != $request->status){
  1147. $compound->status = $request->status;
  1148. $compound->catatan_dari_admin = $request->remark;
  1149. $compound->amount_payment = $request->amount;
  1150. $compound->update_by = $request->current_id;
  1151. $saved = $compound->save();
  1152. if($saved){
  1153. $gDate = $compound->created_at->format('F Y');
  1154. $historyData = [
  1155. 'tarikh_kumpulan' => $gDate,
  1156. ];
  1157. $subHistory = [
  1158. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1159. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1160. '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>",
  1161. ];
  1162. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1163. if(!empty($groupByDate)){
  1164. $groupByDate->subhistory()->create($subHistory);
  1165. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1166. }else{
  1167. $history = History::create($historyData);
  1168. $history->subhistory()->create($subHistory);
  1169. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1170. }
  1171. if($request->status == "Berbayar"){
  1172. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1173. }else{
  1174. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1175. }
  1176. }else{
  1177. $response = [
  1178. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1179. ];
  1180. return response()->json($response, 200);
  1181. }
  1182. }else{
  1183. if($request->remark != ''){
  1184. $compound->catatan_dari_admin = $request->remark;
  1185. $compound->update_by = $request->current_id;
  1186. $compound->save();
  1187. $saved = $compound->save();
  1188. if($saved){
  1189. $gDate = $compound->created_at->format('F Y');
  1190. $historyData = [
  1191. 'tarikh_kumpulan' => $gDate,
  1192. ];
  1193. $subHistory = [
  1194. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1195. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1196. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1197. ];
  1198. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1199. if(!empty($groupByDate)){
  1200. $groupByDate->subhistory()->create($subHistory);
  1201. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1202. }else{
  1203. $history = History::create($historyData);
  1204. $history->subhistory()->create($subHistory);
  1205. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1206. }
  1207. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1208. }else{
  1209. $response = [
  1210. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1211. ];
  1212. return response()->json($response, 200);
  1213. }
  1214. }else{
  1215. $response = [
  1216. 'success' => false, 'message' => 'Tiada kemaskini!',
  1217. ];
  1218. return response()->json($response, 200);
  1219. }
  1220. }
  1221. }else{
  1222. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1223. $compound->status = $request->status;
  1224. $compound->catatan_dari_admin = $request->remark;
  1225. $compound->amount_payment = $request->amount;
  1226. $compound->update_by = $request->current_id;
  1227. $saved = $compound->save();
  1228. if($saved){
  1229. $gDate = $compound->created_at->format('F Y');
  1230. $historyData = [
  1231. 'tarikh_kumpulan' => $gDate,
  1232. ];
  1233. $subHistory = [
  1234. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1235. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1236. '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>",
  1237. ];
  1238. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1239. if(!empty($groupByDate)){
  1240. $groupByDate->subhistory()->create($subHistory);
  1241. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1242. }else{
  1243. $history = History::create($historyData);
  1244. $history->subhistory()->create($subHistory);
  1245. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1246. }
  1247. if($request->status == "Berbayar"){
  1248. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1249. }else{
  1250. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1251. }
  1252. }else{
  1253. $response = [
  1254. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1255. ];
  1256. return response()->json($response, 200);
  1257. }
  1258. }else{
  1259. if($request->remark != ''){
  1260. $compound->catatan_dari_admin = $request->remark;
  1261. $compound->update_by = $request->current_id;
  1262. $compound->save();
  1263. $saved = $compound->save();
  1264. if($saved){
  1265. $gDate = $compound->created_at->format('F Y');
  1266. $historyData = [
  1267. 'tarikh_kumpulan' => $gDate,
  1268. ];
  1269. $subHistory = [
  1270. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1271. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1272. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1273. ];
  1274. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1275. if(!empty($groupByDate)){
  1276. $groupByDate->subhistory()->create($subHistory);
  1277. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1278. }else{
  1279. $history = History::create($historyData);
  1280. $history->subhistory()->create($subHistory);
  1281. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1282. }
  1283. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1284. }else{
  1285. $response = [
  1286. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1287. ];
  1288. return response()->json($response, 200);
  1289. }
  1290. }else{
  1291. $response = [
  1292. 'success' => false, 'message' => 'Tiada kemaskini!',
  1293. ];
  1294. return response()->json($response, 200);
  1295. }
  1296. }
  1297. }
  1298. }else{
  1299. $response = [
  1300. 'success' => false,
  1301. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  1302. ];
  1303. return response()->json($response, 200);
  1304. }
  1305. }
  1306. /**
  1307. * Remove the specified resource from storage.
  1308. *
  1309. * @param int $id
  1310. * @return \Illuminate\Http\Response
  1311. */
  1312. public function destroy($id)
  1313. {
  1314. //
  1315. }
  1316. }