Dashboard sipadu mbip
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

CompoundResourceController.php 79KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Support\Facades\Log;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Api\BaseController;
  6. use Carbon\Carbon;
  7. use App\Model\Staff;
  8. use App\Model\StaffDetail;
  9. use App\Model\Module\Compound;
  10. use App\Model\Module\Department;
  11. use App\Model\Module\DeedLaw;
  12. use App\Model\Module\Faulty;
  13. use App\Model\Module\ConfidentialFile;
  14. use App\Model\Module\History;
  15. use App\Model\Module\SubHistory;
  16. use App\Model\Module\Memo;
  17. use App\Model\Module\Attachment;
  18. use App\Jobs\StoreCompound;
  19. use App\Jobs\StoreNotice;
  20. use App\Jobs\StoreCompoundEPBT;
  21. use App\Jobs\UpdateCompoundPrice;
  22. use App\Http\Resources\CompoundResource;
  23. class CompoundResourceController extends BaseController
  24. {
  25. /**
  26. * @var ServiceCategory
  27. */
  28. protected $compound;
  29. /**
  30. * ServiceController constructor.
  31. *
  32. * @param ServiceCategory $ServiceCategory
  33. */
  34. public function __construct(Compound $compound)
  35. {
  36. $this->compound = $compound;
  37. }
  38. /**
  39. * Display a listing of the resource.
  40. *
  41. * @return \Illuminate\Http\Response
  42. */
  43. private function searchCompoundAll($jenis,$modul,$status,$start_date,$end_date,$day3, $day7){
  44. $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
  45. $start = $dateS->copy()->startOfDay();
  46. if($end_date != ''){
  47. $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
  48. $end = $dateE->copy()->endOfDay();
  49. }else{
  50. $end = $dateS->copy()->endOfDay();
  51. }
  52. if(!empty($day3))
  53. {
  54. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start->subDays(3), $end->subDays(3)));
  55. }
  56. else if(!empty($day7))
  57. {
  58. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start->subDays(7), $end->subDays(7)));
  59. }
  60. else
  61. {
  62. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start, $end));
  63. }
  64. if($modul == 'All'){
  65. $compound = $compound;
  66. }else if($modul == '06-07'){
  67. $compound = $compound->where(function($q){
  68. // $q->where(function($query){
  69. $q->where('modul', '06')->orWhere('modul','07');
  70. // });
  71. });
  72. }else {
  73. $compound = $compound->where('modul', $modul);
  74. }
  75. if($status == 'All'){
  76. $compound = $compound;
  77. }else {
  78. $compound = $compound->where('status', $status);
  79. }
  80. return $compound;
  81. }
  82. private function searchCompoundAllWithoutDate($jenis,$modul,$status,$day3, $day7){
  83. if(!empty($day3))
  84. {
  85. $compound = Compound::where('jenis', $jenis)->where('created_at', Carbon::now()->subDays(3));
  86. }
  87. else if(!empty($day7))
  88. {
  89. $compound = Compound::where('jenis', $jenis)->where('created_at', Carbon::now()->subDays(7));
  90. }
  91. else
  92. {
  93. $compound = Compound::where('jenis', $jenis);
  94. }
  95. if($modul == 'All'){
  96. $compound = $compound;
  97. }else if($modul == '06-07'){
  98. $compound = $compound->where(function($q){
  99. $q->where(function($query){
  100. $query->where('modul', '06')->orWhere('modul','07');
  101. });
  102. });
  103. }else {
  104. $compound = $compound->where('modul', $modul);
  105. }
  106. if($status == 'All'){
  107. $compound = $compound;
  108. }else {
  109. $compound = $compound->where('status', $status);
  110. }
  111. return $compound;
  112. }
  113. private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date,$day3, $day7){
  114. if(!empty($start_date)){
  115. $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date,$day3, $day7);
  116. }else{
  117. $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status,$day3, $day7);
  118. }
  119. if($enforcer == 'All'){
  120. return $compound;
  121. }else {
  122. $compound = $compound->where('dikeluarkan', $enforcer);
  123. return $compound;
  124. }
  125. }
  126. private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$day3, $day7){
  127. $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date,$day3, $day7);
  128. if($faulty == 'All'){
  129. return $compound->whereIn('jbkod',$department);
  130. }else {
  131. $compound = $compound->where('seksyen_kesalahan', $faulty);
  132. return $compound;
  133. }
  134. }
  135. private function searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$day3, $day7){
  136. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$day3, $day7);
  137. if(!empty($plate_no)){
  138. $compound = $compound->where('no_plate',$plate_no);
  139. return $compound;
  140. }else{
  141. return $compound;
  142. }
  143. }
  144. private function searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$day3, $day7){
  145. $compound = $this->searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$day3, $day7);
  146. if(!empty($kpd)){
  147. if($modul == '02'){
  148. $compound = $compound->where('kpd',$kpd)->orWhere('non', $kpd);
  149. }
  150. else{
  151. $compound = $compound->where('kpd',$kpd);
  152. }
  153. return $compound;
  154. }else{
  155. $compound = $compound->whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal']);
  156. return $compound;
  157. }
  158. }
  159. private function searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$day3, $day7){
  160. $compound = $this->searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$day3, $day7);
  161. if(!empty($company_no)){
  162. $compound = $compound->where('no_daftar_syarikat','LIKE',$company_no);
  163. return $compound;
  164. }else{
  165. return $compound;
  166. }
  167. }
  168. private function searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$day3, $day7){
  169. $compound = $this->searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$day3, $day7);
  170. if(!empty($nric)){
  171. $compound = $compound->where('identity',$nric);
  172. return $compound;
  173. }else{
  174. return $compound;
  175. }
  176. }
  177. private function searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$day3, $day7){
  178. $compound = $this->searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$day3, $day7);
  179. if(!empty($license)){
  180. $compound = $compound->where('no_akaun_lesen', 'exists', true)->where('no_akaun_lesen',$license);
  181. return $compound;
  182. }else{
  183. return $compound;
  184. }
  185. }
  186. private function searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$day3, $day7){
  187. $compound = $this->searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$day3, $day7);
  188. if(!empty($namaP)){
  189. $compound = $compound->where('nama', 'LIKE', "%{$namaP}%");
  190. return $compound;
  191. }else{
  192. return $compound;
  193. }
  194. }
  195. private function searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name,$day3, $day7){
  196. $compound = $this->searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$day3, $day7);
  197. if(!empty($company_name)){
  198. $compound = $compound->where('nama_syarikat', 'exists', true)->where('nama_syarikat', 'LIKE', '%{$company_name%}');
  199. return $compound;
  200. }else{
  201. return $compound;
  202. }
  203. }
  204. public function index(Request $request)
  205. {
  206. // $per_page = '';
  207. // $kpd = '';
  208. // $modul = '02';
  209. // $status = 'All';
  210. // $jenis = 'Pelbagai_JPB';
  211. // if(!empty($request->department)){
  212. // $department = array (
  213. // 0 => '5df355f891d6e66b9c5e626d',
  214. // 1 => '5df721c5cde7fd741433c6b2',
  215. // 2 => '5df722a24636f4594f4a3c3d',
  216. // 3 => '5f17a31795dbfd3320761bfe',
  217. // 4 => '5f3b872fea58cb3c1b0e7b8d',
  218. // );
  219. // }else {
  220. // $department = [];
  221. // }
  222. // // $start_date = '';
  223. // // $end_date = '';
  224. // $start_date = '2020-09-29';
  225. // $end_date = '2020-10-01';
  226. // $enforcer = 'All';
  227. // $faulty = 'All';
  228. // $plate_no = strtolower('');
  229. // $company_no = strtolower('');
  230. // $nric = '';
  231. // $license = '';
  232. // $namaP = '';
  233. // $company_name = '';
  234. // $day3 = 3;
  235. // $day7 = '';
  236. /////////////////////////////////////////////////////////////////////////////////
  237. $per_page = $request->per_page;
  238. $kpd = $request->kpd;
  239. $modul = $request->modul;
  240. $status = $request->status;
  241. $jenis = $request->type;
  242. if(!empty($request->department)){
  243. $department = json_decode($request->department);
  244. }else {
  245. $department = [];
  246. }
  247. $start_date = $request->start_date;
  248. $end_date = $request->end_date;
  249. $enforcer = $request->enforcer;
  250. $faulty = $request->faulty;
  251. $plate_no = strtolower($request->plate_no);
  252. $company_no = strtolower($request->company_no);
  253. $nric = $request->nric;
  254. $license = $request->license;
  255. $namaP = $request->nameP;
  256. $company_name = $request->company_name;
  257. $day3='';
  258. $day7='';
  259. if ($request->has('day3')) {
  260. $day3 = $request->day3; //has() checks if param exist and filled
  261. }
  262. if ($request->has('day7')) {
  263. $day3 = $request->day7; //has() checks if param exist and filled
  264. }
  265. // if (!empty($start_date)) {
  266. // }
  267. $nested_data = array();
  268. $compound = $this->searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name, $day3, $day7)->orderBy('created_at','ASC')->get();
  269. // info($compound);
  270. return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
  271. ->addColumn('index', function($row) {
  272. $curr = Carbon::now();
  273. $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
  274. if($curr->diffInDays($dtC) <= 3){
  275. $html = 'New';
  276. }else{ $html = ''; }
  277. return $html;
  278. })->addColumn('status_kemaskini', function($row) {
  279. $data = '';
  280. if($row['status'] == 'Berbayar'){
  281. if ($row['modul'] == '02') {
  282. $data = '<b>Selesai</b><div style="margin-top: 8px"><span></span><br/></div>';
  283. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  284. }
  285. else{
  286. $data = '<b>'.$row['status'].'</b><div style="margin-top: 8px"><span>Bayaran: </span><br/>';
  287. $data .= 'RM '.$row['amount_payment'].'</div>';
  288. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  289. }
  290. if($row['updated_by'] !== null ){
  291. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  292. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  293. }else {
  294. if(!empty($row['tarikh_bayar']) && $row['tarikh_bayar'] != ''){
  295. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  296. $data .= $row['tarikh_bayar'].' <br/>'.$row['updates_by'].'</div>';
  297. }else {
  298. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  299. $data .= $row['updated_at'].' <br/>'.$row['updates_by'].'</div>';
  300. }
  301. }
  302. }else if($row['status'] == 'Belum Bayar' && $row['updated_by'] !== null){
  303. $data = '<b>'.$row['status'].'</b>';
  304. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  305. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  306. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  307. }else if($row['status'] == 'Batal' && $row['updated_by'] !== null){
  308. $data = '<b>'.$row['status'].'</b>';
  309. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  310. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  311. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  312. }else if($row['status'] == 'Buang' && $row['updated_by'] !== null){
  313. $data = '<b>'.$row['status'].'</b>';
  314. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  315. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  316. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  317. }
  318. else
  319. {
  320. $data = $row['status'];
  321. }
  322. return $data;
  323. })->addColumn('kesalahan', function($row) {
  324. $data = '<b>Seksyen '.$row['faulty_skter'].'</b><br/>'.$row['faulty_name'];
  325. return $data;
  326. })->rawColumns(['index','status_kemaskini','kesalahan'])->make(true);
  327. }
  328. /**
  329. * Show the form for creating a new resource.
  330. *
  331. * @return \Illuminate\Http\Response
  332. */
  333. public function generateNumber($jenis, $tag, $modul)
  334. {
  335. $num= '';
  336. if($modul == '02')
  337. {
  338. //check if theres no 001, start fresh with 0001
  339. if (empty(Compound::where('jenis_n', $jenis)->where('non', $tag.'0001')->first())) {
  340. $num = '0001';
  341. }
  342. else{
  343. //check the lastest compound number stored in dbase filtered by jenis
  344. $notice = Compound::where('jenis_n', $jenis)->withTrashed()->latest()->first();
  345. //sanitize compound number to return only integer
  346. $num = filter_var($notice['non'], FILTER_SANITIZE_NUMBER_INT);
  347. //compulsory increment to store new compound number, WHILE number is found, keep looping
  348. do{
  349. (int)$num += 1;
  350. //add 0s at the fornt if number is less than 1000
  351. if ((strlen((string) $num)) == 1) {
  352. $num = '000'.$num;
  353. }elseif ((strlen((string)$num)) == 2){
  354. $num = '00'.$num;
  355. }elseif ((strlen((string)$num )) == 3) {
  356. $num = '0'.$num;
  357. }
  358. }while(!empty(Compound::where('jenis_n', $jenis)->where('non', $tag.$num)->first()));
  359. }
  360. }else if($modul == '03')
  361. {
  362. //check if theres no 001, start fresh with 0001
  363. if (empty(Compound::where('jenis', $jenis)->where('kpd', $tag.'0001')->first())) {
  364. $num = '0001';
  365. }
  366. else{
  367. //check the lastest compound number stored in dbase filtered by jenis
  368. $compound = Compound::where('jenis', $jenis)->withTrashed()->latest()->first();
  369. //sanitize compound number to return only integer
  370. $num = filter_var($compound['kpd'], FILTER_SANITIZE_NUMBER_INT);
  371. //compulsory increment to store new compound number, WHILE number is found, keep looping
  372. do{
  373. (int)$num += 1;
  374. //add 0s at the fornt if number is less than 1000
  375. if ((strlen((string) $num)) == 1) {
  376. $num = '000'.$num;
  377. }elseif ((strlen((string)$num)) == 2){
  378. $num = '00'.$num;
  379. }elseif ((strlen((string)$num )) == 3) {
  380. $num = '0'.$num;
  381. }
  382. }while(!empty(Compound::where('jenis', $jenis)->where('kpd', $tag.$num)->first()));
  383. }
  384. }
  385. //return kpd with tag
  386. $num = $tag . $num;
  387. return $num;
  388. }
  389. /**
  390. * Store a created compound from notice.
  391. *
  392. * @param \Illuminate\Http\Request $request
  393. * @return \Illuminate\Http\Response
  394. */
  395. public function store(Request $request)
  396. {
  397. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  398. if(empty($staff)){
  399. return $this->sendError('Invalid', 'Staff not existed');
  400. }else {
  401. $saved ='';
  402. $kpd = '';
  403. $no_siri = '';
  404. $data = array();
  405. $faulty = $request->seksyen;
  406. $faulty = Faulty::where('_id',$request->get('seksyen'))->orWhere('nama', 'like', $faulty)->first();
  407. if($request->jenis == 'Parkir')
  408. {
  409. if(!empty($faulty)){
  410. $countKPD = $this->compound->withTrashed()->count();
  411. do {
  412. $countKPD = $countKPD + 1;
  413. } while (!empty(Compound::where("kpd", "=", 'KP'.$countKPD)->first()));
  414. $kpd = 'KP'.$countKPD;
  415. $no_siri = date('yn').'-'.$countKPD;
  416. $fileData = [
  417. 'no_siri' => $no_siri,
  418. ];
  419. //only for compound parkir
  420. $compoundData = [
  421. 'jenis' => 'Parkir',
  422. 'kpd' => 'KPD'.$kpd,
  423. 'nama' => '-',
  424. 'identity' => '-',
  425. 'alamat' => '-',
  426. "no_plate" => strtolower($request->no_plate),
  427. "no_cukai_jalan" => $request->noCukaijalan,
  428. "jenis_kenderaan" => $request->jenisKenderaan,
  429. "model_kenderaan" => $request->modelKenderaan,
  430. "warna_kenderaan" => $request->warnakenderaan,
  431. "nama_kawasan" => $request->namaKawasan,
  432. "nama_taman" => $request->namaTaman,
  433. "nama_jalan" => $request->namaJalan,
  434. "no_parking" => $request->noParking,
  435. "catatan" => $request->catatan,
  436. "lokasi_kejadian" => '-',
  437. 'latlong' => $request->Latlong,
  438. 'jbkod' => $request->jabatan,
  439. 'akta' => $faulty->deed_law_id,
  440. 'seksyen_kesalahan' => $faulty->_id,
  441. 'jumlah_asal_kompaun' => $faulty->amount,
  442. 'jumlah_kemaskini_kompaun' => '-',
  443. 'dikeluarkan' => $staff->_id,
  444. "status" => 'Belum Bayar',
  445. "amount_payment" => '-',
  446. "receipt" => '-',
  447. "modul" => '03',
  448. "penguatkuasa" => '-',
  449. "cpn_created" => Carbon::now()->toDateTimeString(),
  450. ];
  451. $file = ConfidentialFile::create($fileData);
  452. $saved = $file->compound()->create($compoundData);
  453. }
  454. }elseif(($request->jenis == 'Pelbagai_KT') || ($request->jenis == 'Pelbagai_JPB') || ($request->jenis == 'Pelbagai_PA') || ($request->jenis == 'Pelbagai_LESEN')){
  455. $compound = Compound::where('jenis', $request->jenis)->where('kpd', $kpd)->first();
  456. info($compound);
  457. if(!empty($compound)) {
  458. $saved = '';
  459. if($compound->modul != '03')
  460. {
  461. if($request->jenis == 'Pelbagai_KT'){
  462. $compound->kpd = $this->generateNumber($request->jenis, 'KT', '03');
  463. $compound->jenis = $request->jenis;
  464. $compound->nama = $request->namaP;
  465. $compound->identity = $request->noIc;
  466. $compound->nama_syarikat = $request->namaS;
  467. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  468. $compound->alamat = $request->alamat;
  469. // $compound->no_plate = $request->no_plate;
  470. // $compound->no_cukai_jalan = $request->no_cukai_jalan;
  471. // $compound->nama_kawasan = $request->namaKawasan;
  472. // $compound->nama_taman = $request->namaTaman;
  473. // $compound->nama_jalan = $request->namaJalan;
  474. $compound->catatan = $request->catatan;
  475. $compound->latlong = $request->Latlong;
  476. $compound->akta = $faulty->deed_law_id;
  477. $compound->seksyen_kesalahan = $faulty->_id;
  478. $compound->jumlah_asal_kompaun = $faulty->amount;
  479. $compound->dikeluarkan = $staff->_id;
  480. $compound->status = 'Belum Bayar';
  481. $compound->modul = '03';
  482. $compound->no_telefon = $request->tel;
  483. $compound->no_akaun_lesen = $request->lesen;
  484. $compound->created_c = Carbon::now()->toDateTimeString();
  485. }elseif($request->jenis == 'Pelbagai_JPB'){
  486. $compound->kpd = $this->generateNumber($request->jenis, 'JPB', '03');
  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. // }elseif($request->jenis == 'Pelbagai_PA'){
  511. // $compound->jenis = $request->jenis;
  512. // $compound->nama = $request->namaP;
  513. // $compound->identity = $request->noIc;
  514. // $compound->nama_syarikat = $request->namaS;
  515. // $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  516. // $compound->alamat = $request->alamat;
  517. // // $compound->no_plate = $request->no_plate;
  518. // // $compound->no_cukai_jalan = $request->no_cukai_jalan;
  519. // // $compound->nama_kawasan = $request->namaKawasan;
  520. // // $compound->nama_taman = $request->namaTaman;
  521. // // $compound->nama_jalan = $request->namaJalan;
  522. // $compound->catatan = $request->catatan;
  523. // $compound->latlong = $request->Latlong;
  524. // $compound->akta = $faulty->deed_law_id;
  525. // $compound->seksyen_kesalahan = $faulty->_id;
  526. // $compound->jumlah_asal_kompaun = $faulty->amount;
  527. // $compound->dikeluarkan = $staff->_id;
  528. // $compound->status = 'Belum Bayar';
  529. // $compound->modul = '03';
  530. // $compound->no_telefon = $request->tel;
  531. // $compound->no_akaun_lesen = $request->lesen;
  532. // $compound->bil_haiwan = $request->lesen;
  533. // $compound->created_c = Carbon::now()->toDateTimeString();
  534. // }elseif($request->jenis == 'Pelbagai_LESEN'){
  535. // $compound->jenis = $request->jenis;
  536. // $compound->nama = $request->namaP;
  537. // $compound->identity = $request->noIc;
  538. // $compound->nama_syarikat = $request->namaS;
  539. // $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  540. // $compound->alamat = $request->alamat;
  541. // $compound->no_plate = $request->no_plate;
  542. // $compound->no_cukai_jalan = $request->no_cukai_jalan;
  543. // // $compound->nama_kawasan = $request->namaKawasan;
  544. // // $compound->nama_taman = $request->namaTaman;
  545. // // $compound->nama_jalan = $request->namaJalan;
  546. // $compound->catatan = $request->catatan;
  547. // $compound->latlong = $request->Latlong;
  548. // $compound->akta = $faulty->deed_law_id;
  549. // $compound->seksyen_kesalahan = $faulty->_id;
  550. // $compound->jumlah_asal_kompaun = $faulty->amount;
  551. // $compound->dikeluarkan = $staff->_id;
  552. // $compound->status = 'Belum Bayar';
  553. // $compound->modul = '03';
  554. // $compound->no_telefon = $request->tel;
  555. // $compound->no_akaun_lesen = $request->lesen;
  556. // $compound->created_c = Carbon::now()->toDateTimeString();
  557. // }
  558. $saved = $compound->save();
  559. }
  560. else
  561. {
  562. return $this->sendResponse('', 'Kompaun ini telah dikeluarkan!');
  563. }
  564. if($saved){
  565. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  566. // if(!empty($compound)){
  567. // dispatch(new UpdateCompoundPrice($kpd));
  568. // $tawaran = '';
  569. // if($compound->jumlah_kemaskini_kompaun != ''){
  570. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  571. // }else{
  572. // $tawaran = $compound->jumlah_asal_kompaun;
  573. // }
  574. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  575. array_push($data, array('kpd' => $kpd));
  576. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  577. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  578. // }
  579. }
  580. }
  581. else{
  582. return $this->sendResponse('', 'Kompaun ini tidak dijumpai!');
  583. }
  584. }
  585. }
  586. }
  587. /**
  588. *
  589. * Store a newly created notice
  590. *
  591. **/
  592. public function storeNewNotice(Request $request)
  593. {
  594. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  595. if(empty($staff)){
  596. return $this->sendError('Invalid', 'Staff not existed');
  597. }else {
  598. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  599. if(!empty($faulty)){
  600. $data = array();
  601. $non = '';
  602. // $kpd = '';
  603. $no_siri ='';
  604. $noticeData = [];
  605. // $countKPD = $this->compound->withTrashed()->count(); //for parking numbering
  606. // do {
  607. // $kpd = $kpd + 1;
  608. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  609. // $kpd = 'KP'.$countKPD;
  610. // $no_siri = date('yn').'-'.$countKPD;
  611. // $fileData = [
  612. // 'no_siri' => $no_siri,
  613. // ];
  614. if($request->jenis == 'Parkir'){
  615. //for compound numbering
  616. // $countKPD = $this->compound->withTrashed()->count();
  617. // $kpd = 'KPD'.$countKPD;
  618. // $non = 'KPD'.$countKPD;
  619. // $no_siri = date('yn').'-'.$countKPD.'-0';
  620. // $compoundData = [
  621. // 'jenis' => 'Parkir',
  622. // 'kpd' => $kpd,
  623. // 'non' => $non,
  624. // 'nama' => '-',
  625. // 'identity' => '-',
  626. // 'alamat' => '-',
  627. // "no_plate" => strtolower($request->no_plate),
  628. // "no_cukai_jalan" => $request->noCukaijalan,
  629. // "jenis_kenderaan" => $request->jenisKenderaan,
  630. // "model_kenderaan" => $request->modelKenderaan,
  631. // "warna_kenderaan" => $request->warnakenderaan,
  632. // "nama_kawasan" => $request->namaKawasan,
  633. // "nama_taman" => $request->namaTaman,
  634. // "nama_jalan" => $request->namaJalan,
  635. // "no_parking" => $request->noParking,
  636. // "catatan" => $request->catatan,
  637. // "lokasi_kejadian" => '-',
  638. // 'latlong' => $request->Latlong,
  639. // 'jbkod' => $request->jabatan,
  640. // 'akta' => $faulty->deed_law_id,
  641. // 'seksyen_kesalahan' => $faulty->_id,
  642. // 'jumlah_asal_kompaun' => $faulty->amount,
  643. // 'jumlah_kemaskini_kompaun' => '-',
  644. // 'dikeluarkan' => $staff->_id,
  645. // "status" => 'Belum Bayar',
  646. // "amount_payment" => '-',
  647. // "receipt" => '-',
  648. // "modul" => $request->modul,
  649. // "penguatkuasa" => '-',
  650. // "notis_created" => Carbon::now()->toDateTimeString(),
  651. // ];
  652. }elseif($request->jenis == 'Notis_NKG'){
  653. // $kpd = $this->generateNumber($request->jenis, 'KT', '02');
  654. // $non = 'NKG'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  655. $non = $this->generateNumber($request->jenis, 'NKG', '02');
  656. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-1';
  657. $noticeData = [
  658. 'jenis' => '-',
  659. 'jenis_n' => $request->jenis,
  660. 'kpd' => '-',
  661. 'non' => $non,
  662. 'nama' => $request->namaP,
  663. 'identity' => $request->noIc,
  664. 'nama_syarikat' => $request->namaS,
  665. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  666. 'alamat' => $request->alamat,
  667. // "no_plate" => $request->no_plate,
  668. // "no_cukai_jalan" => $request->no_cukai_jalan,
  669. "nama_kawasan" => $request->namaKawasan,
  670. "nama_taman" => $request->namaTaman,
  671. "nama_jalan" => $request->namaJalan,
  672. "catatan" => $request->catatan,
  673. // "lokasi_kejadian" => '-',
  674. 'latlong' => $request->Latlong,
  675. 'jbkod_n' => $request->jabatan,
  676. 'akta_n' => $faulty->deed_law_id,
  677. 'seksyen_kesalahan_n' => $faulty->_id,
  678. // 'jumlah_asal_kompaun' => $faulty->amount,
  679. // 'jumlah_kemaskini_kompaun' => '-',
  680. 'dikeluarkan_n' => $staff->_id,
  681. "status" => 'Belum Bayar',
  682. // "amount_payment" => '-',
  683. // "receipt" => '-',
  684. "modul" => $request->modul,
  685. "penguatkuasa" => '-',
  686. "no_telefon" => $request->tel,
  687. "no_akaun_lesen" => $request->lesen,
  688. "maklumat_tambahan" => '-',
  689. "tindakan" => $request->tindakan,
  690. "tempoh" => $request->tempoh,
  691. "created_n" => Carbon::now()->toDateTimeString(),
  692. ];
  693. }elseif($request->jenis == 'Notis_NMH'){
  694. // $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  695. // $non = 'NMH'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  696. $non = $this->generateNumber($request->jenis, 'NMH', '02');
  697. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-2';
  698. $noticeData = [
  699. 'jenis' => '-',
  700. 'jenis_n' => $request->jenis,
  701. 'kpd' => '-',
  702. 'non' => $non,
  703. 'nama' => $request->namaP,
  704. 'identity' => $request->noIc,
  705. 'nama_syarikat' => $request->namaS,
  706. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  707. 'alamat' => $request->alamat,
  708. // "no_plate" => $request->no_plate,
  709. // "no_cukai_jalan" => $request->no_cukai_jalan,
  710. "nama_kawasan" => $request->namaKawasan,
  711. "nama_taman" => $request->namaTaman,
  712. "nama_jalan" => $request->namaJalan,
  713. "catatan" => $request->catatan,
  714. // "lokasi_kejadian" => '-',
  715. 'latlong' => $request->Latlong,
  716. 'jbkod_n' => $request->jabatan,
  717. 'akta_n' => $faulty->deed_law_id,
  718. 'seksyen_kesalahan_n' => $faulty->_id,
  719. // 'jumlah_asal_kompaun' => $faulty->amount,
  720. // 'jumlah_kemaskini_kompaun' => '-',
  721. 'dikeluarkan_n' => $staff->_id,
  722. "status" => 'Belum Bayar',
  723. // "amount_payment" => '-',
  724. // "receipt" => '-',
  725. "modul" => $request->modul,
  726. "penguatkuasa" => '-',
  727. "no_telefon" => $request->tel,
  728. "no_akaun_lesen" => $request->lesen,
  729. "maklumat_tambahan" => '-',
  730. "tindakan" => $request->tindakan,
  731. "tempoh" => $request->tempoh,
  732. "created_n" => Carbon::now()->toDateTimeString(),
  733. ];
  734. }
  735. elseif($request->jenis == 'Notis_NHN'){
  736. //HN bcs other N stands for notice. compound number no need front N
  737. // $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  738. // $non = 'NHN'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  739. $non = $this->generateNumber($request->jenis, 'NHN', '02' );
  740. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-3';
  741. $noticeData = [
  742. 'jenis' => '-',
  743. 'jenis_n' => $request->jenis,
  744. 'kpd' => '-',
  745. 'non' => $non,
  746. 'nama' => $request->namaP,
  747. 'identity' => $request->noIc,
  748. 'nama_syarikat' => $request->namaS,
  749. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  750. 'alamat' => $request->alamat,
  751. // "no_plate" => $request->no_plate,
  752. // "no_cukai_jalan" => $request->no_cukai_jalan,
  753. "nama_kawasan" => $request->namaKawasan,
  754. "nama_taman" => $request->namaTaman,
  755. "nama_jalan" => $request->namaJalan,
  756. "catatan" => $request->catatan,
  757. // "lokasi_kejadian" => '-',
  758. 'latlong' => $request->Latlong,
  759. 'jbkod_n' => $request->jabatan,
  760. 'akta_n' => $faulty->deed_law_id,
  761. 'seksyen_kesalahan_n' => $faulty->_id,
  762. // 'jumlah_asal_kompaun' => $faulty->amount,
  763. // 'jumlah_kemaskini_kompaun' => '-',
  764. 'dikeluarkan_n' => $staff->_id,
  765. "status" => 'Belum Bayar',
  766. // "amount_payment" => '-',
  767. // "receipt" => '-',
  768. "modul" => $request->modul,
  769. "penguatkuasa" => '-',
  770. "no_telefon" => $request->tel,
  771. "no_akaun_lesen" => $request->lesen,
  772. "maklumat_tambahan" => '-',
  773. "tindakan" => $request->tindakan,
  774. "tempoh" => $request->tempoh,
  775. "created_n" => Carbon::now()->toDateTimeString(),
  776. ];
  777. }
  778. elseif($request->jenis == 'Notis_PA'){
  779. // $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  780. // $non = 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  781. $non = $this->generateNumber($request->jenis, 'PA', '02');
  782. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-4';
  783. $noticeData = [
  784. 'jenis' => '-',
  785. 'jenis_n' => $request->jenis,
  786. 'kpd' => '-',
  787. 'non' => $non,
  788. 'nama' => $request->namaP,
  789. 'identity' => $request->noIc,
  790. 'nama_syarikat' => $request->namaS,
  791. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  792. 'alamat' => $request->alamat,
  793. // "no_plate" => $request->no_plate,
  794. // "no_cukai_jalan" => $request->no_cukai_jalan,
  795. "nama_kawasan" => $request->namaKawasan,
  796. "nama_taman" => $request->namaTaman,
  797. "nama_jalan" => $request->namaJalan,
  798. "catatan" => $request->catatan,
  799. // "lokasi_kejadian" => '-',
  800. 'latlong' => $request->Latlong,
  801. 'jbkod_n' => $request->jabatan,
  802. 'akta_n' => $faulty->deed_law_id,
  803. 'seksyen_kesalahan_n' => $faulty->_id,
  804. // 'jumlah_asal_kompaun' => $faulty->amount,
  805. // 'jumlah_kemaskini_kompaun' => '-',
  806. 'dikeluarkan_n' => $staff->_id,
  807. "status" => 'Belum Bayar',
  808. // "amount_payment" => '-',
  809. // "receipt" => '-',
  810. "modul" => $request->modul,
  811. "penguatkuasa" => '-',
  812. "no_telefon" => $request->tel,
  813. "no_akaun_lesen" => $request->lesen,
  814. "maklumat_tambahan" => '-',
  815. "tindakan" => $request->tindakan,
  816. "tempoh" => $request->tempoh,
  817. "bil_haiwan" => $request->bil_haiwan,
  818. "created_n" => Carbon::now()->toDateTimeString(),
  819. ];
  820. }elseif($request->jenis == 'Notis_NPPM'){
  821. // $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  822. // $non = 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  823. $non = $this->generateNumber($request->jenis, 'NPPM', '02');
  824. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-4';
  825. $noticeData = [
  826. 'jenis' => '-',
  827. 'jenis_n' => $request->jenis,
  828. 'kpd' => '-',
  829. 'non' => $non,
  830. 'nama' => $request->namaP,
  831. 'identity' => $request->noIc,
  832. 'nama_syarikat' => $request->namaS,
  833. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  834. 'alamat' => $request->alamat,
  835. // "no_plate" => $request->no_plate,
  836. // "no_cukai_jalan" => $request->no_cukai_jalan,
  837. "nama_kawasan" => $request->namaKawasan,
  838. "nama_taman" => $request->namaTaman,
  839. "nama_jalan" => $request->namaJalan,
  840. "catatan" => $request->catatan,
  841. // "lokasi_kejadian" => '-',
  842. 'latlong' => $request->Latlong,
  843. 'jbkod_n' => $request->jabatan,
  844. 'akta_n' => $faulty->deed_law_id,
  845. 'seksyen_kesalahan_n' => $faulty->_id,
  846. // 'jumlah_asal_kompaun' => $faulty->amount,
  847. // 'jumlah_kemaskini_kompaun' => '-',
  848. 'dikeluarkan_n' => $staff->_id,
  849. "status" => 'Belum Bayar',
  850. // "amount_payment" => '-',
  851. // "receipt" => '-',
  852. "modul" => $request->modul,
  853. "penguatkuasa" => '-',
  854. "no_telefon" => $request->tel,
  855. "no_akaun_lesen" => $request->lesen,
  856. "maklumat_tambahan" => '-',
  857. "tindakan" => $request->tindakan,
  858. "tempoh" => $request->tempoh,
  859. "bil_haiwan" => $request->bil_haiwan,
  860. "created_n" => Carbon::now()->toDateTimeString(),
  861. ];
  862. }
  863. $fileData = [
  864. 'no_siri' => $no_siri,
  865. ];
  866. $file = ConfidentialFile::create($fileData);
  867. $saved = $file->compound()->create($noticeData);
  868. if($saved){
  869. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  870. // if(!empty($compound)){
  871. // dispatch(new UpdateCompoundPrice($kpd));
  872. // $tawaran = '';
  873. // if($compound->jumlah_kemaskini_kompaun != ''){
  874. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  875. // }else{
  876. // $tawaran = $compound->jumlah_asal_kompaun;
  877. // }
  878. $this->dispatch(new StoreNotice($request->all(), $non, $staff->_id, $no_siri));
  879. //mobile already accept 'kpd' string, so no need to change string name to 'notis'.
  880. array_push($data, array(
  881. 'kpd' => '-',
  882. 'non' => $non
  883. ));
  884. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  885. // }
  886. }
  887. }
  888. }
  889. }
  890. /**
  891. * Store a newly created compound (parkir, KT, JPB).
  892. *
  893. * @param \Illuminate\Http\Request $request
  894. * @return \Illuminate\Http\Response
  895. */
  896. public function storeNewCompound(Request $request)
  897. {
  898. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  899. if(empty($staff)){
  900. return $this->sendError('Invalid', 'Staff not existed');
  901. }else {
  902. $data = array();
  903. // dd($this->compound->where('jenis', 'Parkir')->withTrashed()->count());
  904. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  905. if(!empty($faulty)){
  906. $kpd = '';
  907. $no_siri ='';
  908. // $countKPD = $this->compound->withTrashed()->count();
  909. // do {
  910. // $countKPD = $countKPD + 1;
  911. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  912. // $kpd = $countKPD;
  913. // $no_siri = date('yn').'-'.$countKPD;
  914. // $fileData = [
  915. // 'no_siri' => $no_siri,
  916. // ];
  917. if($request->jenis == 'Parkir')
  918. {
  919. //for compound numbering
  920. $countKPD = $this->compound->where('jenis','Parkir')->withTrashed()->count();
  921. $kpd = 'KPD'.$countKPD;
  922. $no_siri = date('yn').'-'.$countKPD.'-0';
  923. //only for compound parkir
  924. $compoundData = [
  925. 'jenis' => 'Parkir',
  926. 'kpd' => $kpd,
  927. 'nama' => '-',
  928. 'identity' => '-',
  929. 'alamat' => '-',
  930. "no_plate" => strtolower($request->no_plate),
  931. "no_cukai_jalan" => $request->noCukaijalan,
  932. "jenis_kenderaan" => $request->jenisKenderaan,
  933. "model_kenderaan" => $request->modelKenderaan,
  934. "warna_kenderaan" => $request->warnakenderaan,
  935. "nama_kawasan" => $request->namaKawasan,
  936. "nama_taman" => $request->namaTaman,
  937. "nama_jalan" => $request->namaJalan,
  938. "no_parking" => $request->noParking,
  939. "catatan" => $request->catatan,
  940. "lokasi_kejadian" => '-',
  941. 'latlong' => $request->Latlong,
  942. 'jbkod' => $request->jabatan,
  943. 'akta' => $faulty->deed_law_id,
  944. 'seksyen_kesalahan' => $faulty->_id,
  945. 'jumlah_asal_kompaun' => $faulty->amount,
  946. 'jumlah_kemaskini_kompaun' => '-',
  947. 'dikeluarkan' => $staff->_id,
  948. "status" => 'Belum Bayar',
  949. "amount_payment" => '-',
  950. "receipt" => '-',
  951. "modul" => '03',
  952. "penguatkuasa" => '-',
  953. "created_c" => Carbon::now()->toDateTimeString(),
  954. ];
  955. }
  956. if ($request->jenis == 'Pelbagai_KT') {
  957. $kpd = $this->generateNumber($request->jenis, 'KT', '03');
  958. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  959. $compoundData = [
  960. 'jenis' => $request->jenis,
  961. 'kpd' => $kpd,
  962. 'nama' => $request->namaP,
  963. 'identity' => $request->noIc,
  964. 'nama_syarikat' => $request->namaS,
  965. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  966. 'alamat' => $request->alamat,
  967. // "no_plate" => $request->no_plate,
  968. // "no_cukai_jalan" => $request->no_cukai_jalan,
  969. "nama_kawasan" => $request->namaKawasan,
  970. "nama_taman" => $request->namaTaman,
  971. "nama_jalan" => $request->namaJalan,
  972. "catatan" => $request->catatan,
  973. // "lokasi_kejadian" => '-',
  974. 'latlong' => $request->Latlong,
  975. 'jbkod' => $request->jabatan,
  976. 'akta' => $faulty->deed_law_id,
  977. 'seksyen_kesalahan' => $faulty->_id,
  978. 'jumlah_asal_kompaun' => $faulty->amount,
  979. 'jumlah_kemaskini_kompaun' => '-',
  980. 'dikeluarkan' => $staff->_id,
  981. "status" => 'Belum Bayar',
  982. "amount_payment" => '-',
  983. "receipt" => '-',
  984. "modul" => $request->modul,
  985. "penguatkuasa" => '-',
  986. "no_telefon" => $request->tel,
  987. "no_akaun_lesen" => $request->lesen,
  988. "maklumat_tambahan" => '-',
  989. "tindakan" => '-',
  990. "tempoh" => '-',
  991. "created_c" => Carbon::now()->toDateTimeString(),
  992. ];
  993. }
  994. elseif ($request->jenis == 'Pelbagai_JPB') {
  995. $kpd = $this->generateNumber($request->jenis, 'JPB', '03');
  996. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  997. $compoundData = [
  998. 'jenis' => $request->jenis,
  999. 'kpd' => $kpd,
  1000. 'nama' => $request->namaP,
  1001. 'identity' => $request->noIc,
  1002. 'nama_syarikat' => $request->namaS,
  1003. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  1004. 'alamat' => $request->alamat,
  1005. // "no_plate" => $request->no_plate,
  1006. // "no_cukai_jalan" => $request->no_cukai_jalan,
  1007. "nama_kawasan" => $request->namaKawasan,
  1008. "nama_taman" => $request->namaTaman,
  1009. "nama_jalan" => $request->namaJalan,
  1010. "catatan" => $request->catatan,
  1011. // "lokasi_kejadian" => '-',
  1012. 'latlong' => $request->Latlong,
  1013. 'jbkod' => $request->jabatan,
  1014. 'akta' => $faulty->deed_law_id,
  1015. 'seksyen_kesalahan' => $faulty->_id,
  1016. 'jumlah_asal_kompaun' => $faulty->amount,
  1017. 'jumlah_kemaskini_kompaun' => '-',
  1018. 'dikeluarkan' => $staff->_id,
  1019. "status" => 'Belum Bayar',
  1020. "amount_payment" => '-',
  1021. "receipt" => '-',
  1022. "modul" => $request->modul,
  1023. "penguatkuasa" => '-',
  1024. "no_telefon" => $request->tel,
  1025. "no_akaun_lesen" => $request->lesen,
  1026. "maklumat_tambahan" => '-',
  1027. "tindakan" => '-',
  1028. "tempoh" => '-',
  1029. "created_c" => Carbon::now()->toDateTimeString(),
  1030. ];
  1031. }
  1032. // elseif ($request->jenis == 'Pelbagai_LESEN') {
  1033. // //HN bcs other N stands for notice. compound number no need front N
  1034. // $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  1035. // $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-3';
  1036. // $compoundData = [
  1037. // 'jenis' => $request->jenis,
  1038. // 'kpd' => $kpd,
  1039. // 'nama' => $request->namaP,
  1040. // 'identity' => $request->noIc,
  1041. // 'nama_syarikat' => $request->namaS,
  1042. // 'no_daftar_syarikat' => strtolower($request->daftarNo),
  1043. // 'alamat' => $request->alamat,
  1044. // "no_plate" => $request->no_plate,
  1045. // "no_cukai_jalan" => $request->no_cukai_jalan,
  1046. // "nama_kawasan" => $request->namaKawasan,
  1047. // "nama_taman" => $request->namaTaman,
  1048. // "nama_jalan" => $request->namaJalan,
  1049. // "catatan" => $request->catatan,
  1050. // "lokasi_kejadian" => '-',
  1051. // 'latlong' => $request->Latlong,
  1052. // 'jbkod' => $request->jabatan,
  1053. // 'akta' => $faulty->deed_law_id,
  1054. // 'seksyen_kesalahan' => $faulty->_id,
  1055. // 'jumlah_asal_kompaun' => $faulty->amount,
  1056. // 'jumlah_kemaskini_kompaun' => '-',
  1057. // 'dikeluarkan' => $staff->_id,
  1058. // "status" => 'Belum Bayar',
  1059. // "amount_payment" => '-',
  1060. // "receipt" => '-',
  1061. // "modul" => $request->modul,
  1062. // "penguatkuasa" => '-',
  1063. // "no_telefon" => $request->tel,
  1064. // "no_akaun_lesen" => $request->lesen,
  1065. // "maklumat_tambahan" => '-',
  1066. // "created_c" => Carbon::now()->toDateTimeString(),
  1067. // ];
  1068. // }
  1069. // else if($request->jenis == 'Pelbagai_PA'){
  1070. // $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  1071. // $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-4';
  1072. // $compoundData = [
  1073. // 'jenis' => $request->jenis,
  1074. // 'kpd' => $kpd,
  1075. // 'nama' => $request->namaP,
  1076. // 'identity' => $request->noIc,
  1077. // 'nama_syarikat' => $request->namaS,
  1078. // 'no_daftar_syarikat' => strtolower($request->daftarNo),
  1079. // 'alamat' => $request->alamat,
  1080. // "no_plate" => $request->no_plate,
  1081. // "no_cukai_jalan" => $request->no_cukai_jalan,
  1082. // "nama_kawasan" => $request->namaKawasan,
  1083. // "nama_taman" => $request->namaTaman,
  1084. // "nama_jalan" => $request->namaJalan,
  1085. // "catatan" => $request->catatan,
  1086. // "lokasi_kejadian" => '-',
  1087. // 'latlong' => $request->Latlong,
  1088. // 'jbkod' => $request->jabatan,
  1089. // 'akta' => $faulty->deed_law_id,
  1090. // 'seksyen_kesalahan' => $faulty->_id,
  1091. // 'jumlah_asal_kompaun' => $faulty->amount,
  1092. // 'jumlah_kemaskini_kompaun' => '-',
  1093. // 'dikeluarkan' => $staff->_id,
  1094. // "status" => 'Belum Bayar',
  1095. // "amount_payment" => '-',
  1096. // "receipt" => '-',
  1097. // "modul" => $request->modul,
  1098. // "penguatkuasa" => '-',
  1099. // "no_telefon" => $request->tel,
  1100. // "no_akaun_lesen" => $request->lesen,
  1101. // "maklumat_tambahan" => '-',
  1102. // "bil_haiwan" => $request->bil_haiwan,
  1103. // "cpn_created" => Carbon::now()->toDateTimeString(),
  1104. // ];
  1105. // }
  1106. $fileData = [
  1107. 'no_siri' => $no_siri,
  1108. ];
  1109. $file = ConfidentialFile::create($fileData);
  1110. $saved = $file->compound()->create($compoundData);
  1111. if($saved){
  1112. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  1113. // if(!empty($compound)){
  1114. // dispatch(new UpdateCompoundPrice($kpd));
  1115. // $tawaran = '';
  1116. // if($compound->jumlah_kemaskini_kompaun != ''){
  1117. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  1118. // }else{
  1119. // $tawaran = $compound->jumlah_asal_kompaun;
  1120. // }
  1121. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  1122. array_push($data, array('kpd' => $kpd));
  1123. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  1124. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  1125. }
  1126. return $this->sendError('', 'Tidak berjaya simpan rekod kompaun!');
  1127. }
  1128. return $this->sendResponse('Tidak Berjaya!', 'Kesalahan tidak dijumpai!');
  1129. }
  1130. }
  1131. /**
  1132. * Display the specified resource.
  1133. *
  1134. * @param int $id
  1135. * @return \Illuminate\Http\Response
  1136. */
  1137. public function show($id)
  1138. {
  1139. //
  1140. }
  1141. /**
  1142. * Show the form for editing the specified resource.
  1143. *
  1144. * @param int $id
  1145. * @return \Illuminate\Http\Response
  1146. */
  1147. public function edit($id)
  1148. {
  1149. //
  1150. }
  1151. /**
  1152. * Update the specified resource in storage.
  1153. *
  1154. * @param \Illuminate\Http\Request $request
  1155. * @param int $id
  1156. * @return \Illuminate\Http\Response
  1157. */
  1158. public function update(Request $request, $id)
  1159. {
  1160. //
  1161. }
  1162. public function updateStatusNoticeViaDashboard(Request $request)
  1163. {
  1164. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1165. $staff = StaffDetail::find($request->current_id);
  1166. if(!empty($compound) && !empty($staff)){
  1167. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1168. if($compound->status != $request->status){
  1169. $compound->status = $request->status;
  1170. $compound->catatan_dari_admin = $request->remark;
  1171. $compound->update_by = $request->current_id;
  1172. $saved = $compound->save();
  1173. if($saved){
  1174. $gDate = $compound->created_at->format('F Y');
  1175. $historyData = [
  1176. 'tarikh_kumpulan' => $gDate,
  1177. ];
  1178. $subHistory = [
  1179. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1180. 'tajuk' => "Status notis ".$compound->kpd. " telah dikemaskini",
  1181. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1182. ];
  1183. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1184. if(!empty($groupByDate)){
  1185. $groupByDate->subhistory()->create($subHistory);
  1186. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1187. }else{
  1188. $history = History::create($historyData);
  1189. $history->subhistory()->create($subHistory);
  1190. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1191. }
  1192. if($request->status == "Berbayar"){
  1193. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1194. }else{
  1195. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1196. }
  1197. }else{
  1198. $response = [
  1199. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1200. ];
  1201. return response()->json($response, 200);
  1202. }
  1203. }else{
  1204. if($request->remark != ''){
  1205. $compound->catatan_dari_admin = $request->remark;
  1206. $compound->update_by = $request->current_id;
  1207. $compound->save();
  1208. $saved = $compound->save();
  1209. if($saved){
  1210. $gDate = $compound->created_at->format('F Y');
  1211. $historyData = [
  1212. 'tarikh_kumpulan' => $gDate,
  1213. ];
  1214. $subHistory = [
  1215. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1216. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1217. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1218. ];
  1219. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1220. if(!empty($groupByDate)){
  1221. $groupByDate->subhistory()->create($subHistory);
  1222. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1223. }else{
  1224. $history = History::create($historyData);
  1225. $history->subhistory()->create($subHistory);
  1226. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1227. }
  1228. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1229. }else{
  1230. $response = [
  1231. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1232. ];
  1233. return response()->json($response, 200);
  1234. }
  1235. }else{
  1236. $response = [
  1237. 'success' => false, 'message' => 'Tiada kemaskini!',
  1238. ];
  1239. return response()->json($response, 200);
  1240. }
  1241. }
  1242. }else{
  1243. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1244. $compound->status = $request->status;
  1245. $compound->catatan_dari_admin = $request->remark;
  1246. // $compound->amount_payment = $request->amount;
  1247. $compound->update_by = $request->current_id;
  1248. $saved = $compound->save();
  1249. if($saved){
  1250. $gDate = $compound->created_at->format('F Y');
  1251. $historyData = [
  1252. 'tarikh_kumpulan' => $gDate,
  1253. ];
  1254. $subHistory = [
  1255. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1256. 'tajuk' => "Status notis telah dikemaskini",
  1257. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1258. ];
  1259. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1260. if(!empty($groupByDate)){
  1261. $groupByDate->subhistory()->create($subHistory);
  1262. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1263. }else{
  1264. $history = History::create($historyData);
  1265. $history->subhistory()->create($subHistory);
  1266. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1267. }
  1268. if($request->status == "Berbayar"){
  1269. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1270. }else{
  1271. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1272. }
  1273. }else{
  1274. $response = [
  1275. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1276. ];
  1277. return response()->json($response, 200);
  1278. }
  1279. }else{
  1280. if($request->remark != ''){
  1281. $compound->catatan_dari_admin = $request->remark;
  1282. $compound->update_by = $request->current_id;
  1283. $compound->save();
  1284. $saved = $compound->save();
  1285. if($saved){
  1286. $gDate = $compound->created_at->format('F Y');
  1287. $historyData = [
  1288. 'tarikh_kumpulan' => $gDate,
  1289. ];
  1290. $subHistory = [
  1291. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1292. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1293. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1294. ];
  1295. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1296. if(!empty($groupByDate)){
  1297. $groupByDate->subhistory()->create($subHistory);
  1298. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1299. }else{
  1300. $history = History::create($historyData);
  1301. $history->subhistory()->create($subHistory);
  1302. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1303. }
  1304. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1305. }else{
  1306. $response = [
  1307. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1308. ];
  1309. return response()->json($response, 200);
  1310. }
  1311. }else{
  1312. $response = [
  1313. 'success' => false, 'message' => 'Tiada kemaskini!',
  1314. ];
  1315. return response()->json($response, 200);
  1316. }
  1317. }
  1318. }
  1319. }else{
  1320. $response = [
  1321. 'success' => false,
  1322. 'message' => 'Notis ini tidak dijumpai / staff tidak ditemui',
  1323. ];
  1324. return response()->json($response, 200);
  1325. }
  1326. }
  1327. public function updateStatusPaymentViaDashboard(Request $request)
  1328. {
  1329. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1330. $staff = StaffDetail::find($request->current_id);
  1331. if(!empty($compound) && !empty($staff)){
  1332. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1333. if($compound->status != $request->status){
  1334. $compound->status = $request->status;
  1335. $compound->catatan_dari_admin = $request->remark;
  1336. $compound->amount_payment = $request->amount;
  1337. $compound->update_by = $request->current_id;
  1338. $saved = $compound->save();
  1339. if($saved){
  1340. $gDate = $compound->created_at->format('F Y');
  1341. $historyData = [
  1342. 'tarikh_kumpulan' => $gDate,
  1343. ];
  1344. $subHistory = [
  1345. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1346. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1347. '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>",
  1348. ];
  1349. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1350. if(!empty($groupByDate)){
  1351. $groupByDate->subhistory()->create($subHistory);
  1352. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1353. }else{
  1354. $history = History::create($historyData);
  1355. $history->subhistory()->create($subHistory);
  1356. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1357. }
  1358. if($request->status == "Berbayar"){
  1359. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1360. }else{
  1361. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1362. }
  1363. }else{
  1364. $response = [
  1365. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1366. ];
  1367. return response()->json($response, 200);
  1368. }
  1369. }else{
  1370. if($request->remark != ''){
  1371. $compound->catatan_dari_admin = $request->remark;
  1372. $compound->update_by = $request->current_id;
  1373. $compound->save();
  1374. $saved = $compound->save();
  1375. if($saved){
  1376. $gDate = $compound->created_at->format('F Y');
  1377. $historyData = [
  1378. 'tarikh_kumpulan' => $gDate,
  1379. ];
  1380. $subHistory = [
  1381. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1382. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1383. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1384. ];
  1385. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1386. if(!empty($groupByDate)){
  1387. $groupByDate->subhistory()->create($subHistory);
  1388. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1389. }else{
  1390. $history = History::create($historyData);
  1391. $history->subhistory()->create($subHistory);
  1392. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1393. }
  1394. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1395. }else{
  1396. $response = [
  1397. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1398. ];
  1399. return response()->json($response, 200);
  1400. }
  1401. }else{
  1402. $response = [
  1403. 'success' => false, 'message' => 'Tiada kemaskini!',
  1404. ];
  1405. return response()->json($response, 200);
  1406. }
  1407. }
  1408. }else{
  1409. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1410. $compound->status = $request->status;
  1411. $compound->catatan_dari_admin = $request->remark;
  1412. $compound->amount_payment = $request->amount;
  1413. $compound->update_by = $request->current_id;
  1414. $saved = $compound->save();
  1415. if($saved){
  1416. $gDate = $compound->created_at->format('F Y');
  1417. $historyData = [
  1418. 'tarikh_kumpulan' => $gDate,
  1419. ];
  1420. $subHistory = [
  1421. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1422. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1423. '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>",
  1424. ];
  1425. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1426. if(!empty($groupByDate)){
  1427. $groupByDate->subhistory()->create($subHistory);
  1428. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1429. }else{
  1430. $history = History::create($historyData);
  1431. $history->subhistory()->create($subHistory);
  1432. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1433. }
  1434. if($request->status == "Berbayar"){
  1435. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1436. }else{
  1437. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1438. }
  1439. }else{
  1440. $response = [
  1441. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1442. ];
  1443. return response()->json($response, 200);
  1444. }
  1445. }else{
  1446. if($request->remark != ''){
  1447. $compound->catatan_dari_admin = $request->remark;
  1448. $compound->update_by = $request->current_id;
  1449. $compound->save();
  1450. $saved = $compound->save();
  1451. if($saved){
  1452. $gDate = $compound->created_at->format('F Y');
  1453. $historyData = [
  1454. 'tarikh_kumpulan' => $gDate,
  1455. ];
  1456. $subHistory = [
  1457. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1458. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1459. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1460. ];
  1461. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1462. if(!empty($groupByDate)){
  1463. $groupByDate->subhistory()->create($subHistory);
  1464. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1465. }else{
  1466. $history = History::create($historyData);
  1467. $history->subhistory()->create($subHistory);
  1468. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1469. }
  1470. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1471. }else{
  1472. $response = [
  1473. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1474. ];
  1475. return response()->json($response, 200);
  1476. }
  1477. }else{
  1478. $response = [
  1479. 'success' => false, 'message' => 'Tiada kemaskini!',
  1480. ];
  1481. return response()->json($response, 200);
  1482. }
  1483. }
  1484. }
  1485. }else{
  1486. $response = [
  1487. 'success' => false,
  1488. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  1489. ];
  1490. return response()->json($response, 200);
  1491. }
  1492. }
  1493. /**
  1494. * Remove the specified resource from storage.
  1495. *
  1496. * @param int $id
  1497. * @return \Illuminate\Http\Response
  1498. */
  1499. public function destroy($id)
  1500. {
  1501. //
  1502. }
  1503. }