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 76KB

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