Dashboard sipadu mbip
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CompoundResourceController.php 58KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Api\BaseController;
  5. use Carbon\Carbon;
  6. use App\Model\Staff;
  7. use App\Model\StaffDetail;
  8. use App\Model\Module\Compound;
  9. use App\Model\Module\Department;
  10. use App\Model\Module\DeedLaw;
  11. use App\Model\Module\Faulty;
  12. use App\Model\Module\ConfidentialFile;
  13. use App\Model\Module\History;
  14. use App\Model\Module\SubHistory;
  15. use App\Model\Module\Memo;
  16. use App\Model\Module\Attachment;
  17. use App\Jobs\StoreCompound;
  18. use App\Jobs\StoreNotice;
  19. use App\Jobs\StoreCompoundEPBT;
  20. use App\Jobs\UpdateCompoundPrice;
  21. use App\Http\Resources\CompoundResource;
  22. class CompoundResourceController extends BaseController
  23. {
  24. /**
  25. * @var ServiceCategory
  26. */
  27. protected $compound;
  28. /**
  29. * ServiceController constructor.
  30. *
  31. * @param ServiceCategory $ServiceCategory
  32. */
  33. public function __construct(Compound $compound)
  34. {
  35. $this->compound = $compound;
  36. }
  37. /**
  38. * Display a listing of the resource.
  39. *
  40. * @return \Illuminate\Http\Response
  41. */
  42. private function searchCompoundAll($jenis,$modul,$status,$start_date,$end_date){
  43. $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
  44. $start = $dateS->copy()->startOfDay();
  45. if($end_date != ''){
  46. $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
  47. $end = $dateE->copy()->endOfDay();
  48. }else{
  49. $end = $dateS->copy()->endOfDay();
  50. }
  51. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start, $end));
  52. if($modul == 'All'){
  53. $compound = $compound;
  54. }else if($modul == '06-07'){
  55. $compound = $compound->where(function($q){
  56. // $q->where(function($query){
  57. $q->where('modul', '06')->orWhere('modul','07');
  58. // });
  59. });
  60. }else if(($modul == '03') || ($modul == '02')){
  61. $compound = $compound->where(function($q){
  62. // $q->where(function($query){
  63. $q->where('modul', '02')->orWhere('modul', '03');
  64. // });
  65. });
  66. }else {
  67. $compound = $compound->where('modul', $modul);
  68. }
  69. if($status == 'All'){
  70. $compound = $compound;
  71. }else {
  72. $compound = $compound->where('status', $status);
  73. }
  74. return $compound;
  75. }
  76. private function searchCompoundAllWithoutDate($jenis,$modul,$status){
  77. $compound = Compound::where('jenis', $jenis);
  78. if($modul == 'All'){
  79. $compound = $compound;
  80. }else if($modul == '06-07'){
  81. $compound = $compound->where(function($q){
  82. $q->where(function($query){
  83. $query->where('modul', '06')->orWhere('modul','07');
  84. });
  85. });
  86. }else if($modul == '03'){
  87. $compound = $compound->where(function($q){
  88. $q->where('modul', '02')->orWhere('modul', '03');
  89. });
  90. }else {
  91. $compound = $compound->where('modul', $modul);
  92. }
  93. if($status == 'All'){
  94. $compound = $compound;
  95. }else {
  96. $compound = $compound->where('status', $status);
  97. }
  98. return $compound;
  99. }
  100. private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date){
  101. if(!empty($start_date)){
  102. $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date);
  103. }else{
  104. $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status);
  105. }
  106. if($enforcer == 'All'){
  107. return $compound;
  108. }else {
  109. $compound = $compound->where('dikeluarkan', $enforcer);
  110. return $compound;
  111. }
  112. }
  113. private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department){
  114. $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date);
  115. if($faulty == 'All'){
  116. return $compound->whereIn('jbkod',$department);
  117. }else {
  118. $compound = $compound->where('seksyen_kesalahan', $faulty);
  119. return $compound;
  120. }
  121. }
  122. private function searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no){
  123. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department);
  124. if(!empty($plate_no)){
  125. $compound = $compound->where('no_plate',$plate_no);
  126. return $compound;
  127. }else{
  128. return $compound;
  129. }
  130. }
  131. private function searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd){
  132. $compound = $this->searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no);
  133. if(!empty($kpd)){
  134. $compound = $compound->where('kpd',$kpd);
  135. return $compound;
  136. }else{
  137. $compound = $compound->whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal']);
  138. return $compound;
  139. }
  140. }
  141. private function searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no){
  142. $compound = $this->searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd);
  143. if(!empty($company_no)){
  144. $compound = $compound->where('no_daftar_syarikat','LIKE',$company_no);
  145. return $compound;
  146. }else{
  147. return $compound;
  148. }
  149. }
  150. private function searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric){
  151. $compound = $this->searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no);
  152. if(!empty($nric)){
  153. $compound = $compound->where('identity',$nric);
  154. return $compound;
  155. }else{
  156. return $compound;
  157. }
  158. }
  159. private function searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license){
  160. $compound = $this->searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric);
  161. if(!empty($license)){
  162. $compound = $compound->where('no_akaun_lesen', 'exists', true)->where('no_akaun_lesen',$license);
  163. return $compound;
  164. }else{
  165. return $compound;
  166. }
  167. }
  168. private function searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP){
  169. $compound = $this->searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license);
  170. if(!empty($namaP)){
  171. $compound = $compound->where('nama', 'LIKE', "%{$namaP}%");
  172. return $compound;
  173. }else{
  174. return $compound;
  175. }
  176. }
  177. private function searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name){
  178. $compound = $this->searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP);
  179. if(!empty($company_name)){
  180. $compound = $compound->where('nama_syarikat', 'exists', true)->where('nama_syarikat', 'LIKE', '%{$company_name%}');
  181. return $compound;
  182. }else{
  183. return $compound;
  184. }
  185. }
  186. public function index(Request $request)
  187. {
  188. // $per_page = '';
  189. // $kpd = '';
  190. // $modul = '02';
  191. // $status = 'All';
  192. // $jenis = 'Pelbagai_JPB';
  193. // if(!empty($request->department)){
  194. // $department = ["5df721c5cde7fd741433c6b2","5d957899f3da686c08192026","5d9d4a699b802d5a31031a8a","5d9d4db1aa95fa07f7245e28","5d9d5955eb4f92300927f188","5d9e965fec0023467756a02a","5d9eba38e4be2267877896a8"];
  195. // }else {
  196. // $department = [];
  197. // }
  198. // $start_date = '2020-08-18';
  199. // $end_date = '2020-09-20';
  200. // $enforcer = 'All';
  201. // $faulty = 'All';
  202. // $plate_no = strtolower('');
  203. // $company_no = strtolower('');
  204. // $nric = '';
  205. // $license = '';
  206. // $namaP = '';
  207. // $company_name = '';
  208. /////////////////////////////////////////////////////////////////////////////////
  209. $per_page = $request->per_page;
  210. $kpd = $request->kpd;
  211. $modul = $request->modul;
  212. $status = $request->status;
  213. $jenis = $request->type;
  214. if(!empty($request->department)){
  215. $department = json_decode($request->department);
  216. }else {
  217. $department = [];
  218. }
  219. $start_date = $request->start_date;
  220. $end_date = $request->end_date;
  221. $enforcer = $request->enforcer;
  222. $faulty = $request->faulty;
  223. $plate_no = strtolower($request->plate_no);
  224. $company_no = strtolower($request->company_no);
  225. $nric = $request->nric;
  226. $license = $request->license;
  227. $namaP = $request->nameP;
  228. $company_name = $request->company_name;
  229. $nested_data = array();
  230. $compound = $this->searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name)->orderBy('created_at','ASC')->get();
  231. return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
  232. ->addColumn('index', function($row) {
  233. $curr = Carbon::now();
  234. $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
  235. if($curr->diffInDays($dtC) <= 3){
  236. $html = 'New';
  237. }else{ $html = ''; }
  238. return $html;
  239. })->addColumn('status_kemaskini', function($row) {
  240. $data = '';
  241. if($row['status'] == 'Berbayar'){
  242. $data = '<b>'.$row['status'].'</b><div style="margin-top: 8px"><span>Bayaran: </span><br/>';
  243. $data .= 'RM '.$row['amount_payment'].'</div>';
  244. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  245. if($row['updated_by'] !== null ){
  246. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  247. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  248. }else {
  249. if(!empty($row['tarikh_bayar']) && $row['tarikh_bayar'] != ''){
  250. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  251. $data .= $row['tarikh_bayar'].' <br/>'.$row['updates_by'].'</div>';
  252. }else {
  253. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  254. $data .= $row['updated_at'].' <br/>'.$row['updates_by'].'</div>';
  255. }
  256. }
  257. }else if($row['status'] == 'Belum Bayar' && $row['updated_by'] !== null){
  258. $data = '<b>'.$row['status'].'</b>';
  259. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  260. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  261. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  262. }else if($row['status'] == 'Batal' && $row['updated_by'] !== null){
  263. $data = '<b>'.$row['status'].'</b>';
  264. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  265. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  266. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  267. }else if($row['status'] == 'Buang' && $row['updated_by'] !== null){
  268. $data = '<b>'.$row['status'].'</b>';
  269. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  270. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  271. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  272. }
  273. else
  274. {
  275. $data = $row['status'];
  276. }
  277. return $data;
  278. })->addColumn('kesalahan', function($row) {
  279. $data = '<b>Seksyen '.$row['faulty_skter'].'</b><br/>'.$row['faulty_name'];
  280. return $data;
  281. })->rawColumns(['index','status_kemaskini','kesalahan'])->make(true);
  282. }
  283. /**
  284. * Show the form for creating a new resource.
  285. *
  286. * @return \Illuminate\Http\Response
  287. */
  288. public function create()
  289. {
  290. //
  291. }
  292. /**
  293. * Store a created compound from notice.
  294. *
  295. * @param \Illuminate\Http\Request $request
  296. * @return \Illuminate\Http\Response
  297. */
  298. public function store(Request $request)
  299. {
  300. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  301. if(empty($staff)){
  302. return $this->sendError('Invalid', 'Staff not existed');
  303. }else {
  304. $saved ='';
  305. $kpd = '';
  306. $no_siri = '';
  307. $data = array();
  308. if($request->jenis == 'Parkir')
  309. {
  310. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  311. if(!empty($faulty)){
  312. $countKPD = $this->compound->withTrashed()->count();
  313. do {
  314. $countKPD = $countKPD + 1;
  315. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  316. $kpd = $countKPD;
  317. $no_siri = date('yn').'-'.$countKPD;
  318. $fileData = [
  319. 'no_siri' => $no_siri,
  320. ];
  321. //only for compound parkir
  322. $compoundData = [
  323. 'jenis' => 'Parkir',
  324. 'kpd' => $kpd,
  325. 'nama' => '-',
  326. 'identity' => '-',
  327. 'alamat' => '-',
  328. "no_plate" => strtolower($request->no_plate),
  329. "no_cukai_jalan" => $request->noCukaijalan,
  330. "jenis_kenderaan" => $request->jenisKenderaan,
  331. "model_kenderaan" => $request->modelKenderaan,
  332. "warna_kenderaan" => $request->warnakenderaan,
  333. "nama_kawasan" => $request->namaKawasan,
  334. "nama_taman" => $request->namaTaman,
  335. "nama_jalan" => $request->namaJalan,
  336. "no_parking" => $request->noParking,
  337. "catatan" => $request->catatan,
  338. "lokasi_kejadian" => '-',
  339. 'latlong' => $request->Latlong,
  340. 'jbkod' => $request->jabatan,
  341. 'akta' => $faulty->deed_law_id,
  342. 'seksyen_kesalahan' => $faulty->_id,
  343. 'jumlah_asal_kompaun' => $faulty->amount,
  344. 'jumlah_kemaskini_kompaun' => '',
  345. 'dikeluarkan' => $staff->_id,
  346. "status" => 'Belum Bayar',
  347. "amount_payment" => '',
  348. "receipt" => '',
  349. "modul" => '03',
  350. "penguatkuasa" => '',
  351. "cpn_created" => Carbon::now()->toDateTimeString(),
  352. ];
  353. $file = ConfidentialFile::create($fileData);
  354. $saved = $file->compound()->create($compoundData);
  355. }
  356. }elseif(($request->jenis == 'Pelbagai_KT') || ($request->jenis == 'Pelbagai_JPB') || ($request->jenis == 'Pelbagai_PA') ||
  357. ($request->jenis == 'Pelbagai_LESEN')){
  358. $kpd = $request->kpd;
  359. $compound = Compound::where('jenis', $request->jenis)->where('kpd', $kpd)->first();
  360. if (!empty($compound)) {
  361. if(!($compound->modul == '03'))
  362. {
  363. if($request->jenis == 'Pelbagai_KT'){
  364. $compound->jenis = $request->jenis;
  365. $compound->nama = $request->namaP;
  366. $compound->identity = $request->noIc;
  367. $compound->nama_syarikat = $request->namaS;
  368. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  369. $compound->alamat = $request->alamat;
  370. $compound->no_plate = $request->no_plate;
  371. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  372. // $compound->nama_kawasan = $request->namaKawasan;
  373. // $compound->nama_taman = $request->namaTaman;
  374. // $compound->nama_jalan = $request->namaJalan;
  375. $compound->catatan = $request->catatan;
  376. $compound->latlong = $request->Latlong;
  377. // $compound->akta = $faulty->deed_law_id;
  378. // $compound->seksyen_kesalahan = $faulty->_id;
  379. // $compound->jumlah_asal_kompaun = $faulty->amount;
  380. $compound->dikeluarkan_ = $staff->_id;
  381. $compound->status = 'Belum Bayar';
  382. $compound->modul = '03';
  383. $compound->no_telefon = $request->tel;
  384. $compound->no_akaun_lesen = $request->lesen;
  385. $compound->cpn_created = Carbon::now()->toDateTimeString();
  386. }elseif($request->jenis == 'Pelbagai_JPB'){
  387. $compound->jenis = $request->jenis;
  388. $compound->nama = $request->namaP;
  389. $compound->identity = $request->noIc;
  390. $compound->nama_syarikat = $request->namaS;
  391. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  392. $compound->alamat = $request->alamat;
  393. $compound->no_plate = $request->no_plate;
  394. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  395. // $compound->nama_kawasan => $request->namaKawasan;
  396. // $compound->nama_taman => $request->namaTaman;
  397. // $compound->nama_jalan => $request->namaJalan;
  398. $compound->catatan = $request->catatan;
  399. $compound->latlong = $request->Latlong;
  400. // $compound->akta => $faulty->deed_law_id;
  401. // $compound->seksyen_kesalahan => $faulty->_id;
  402. // $compound->jumlah_asal_kompaun => $faulty->amount;
  403. $compound->dikeluarkan_ = $staff->_id;
  404. $compound->status = 'Belum Bayar';
  405. $compound->modul = '03';
  406. $compound->no_telefon = $request->tel;
  407. $compound->no_akaun_lesen = $request->lesen;
  408. $compound->cpn_created = Carbon::now()->toDateTimeString();
  409. }elseif($request->jenis == 'Pelbagai_PA'){
  410. $compound->jenis = $request->jenis;
  411. $compound->nama = $request->namaP;
  412. $compound->identity = $request->noIc;
  413. $compound->nama_syarikat = $request->namaS;
  414. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  415. $compound->alamat = $request->alamat;
  416. $compound->no_plate = $request->no_plate;
  417. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  418. // $compound->nama_kawasan = $request->namaKawasan;
  419. // $compound->nama_taman = $request->namaTaman;
  420. // $compound->nama_jalan = $request->namaJalan;
  421. $compound->catatan = $request->catatan;
  422. $compound->latlong = $request->Latlong;
  423. // $compound->akta = $faulty->deed_law_id;
  424. // $compound->seksyen_kesalahan = $faulty->_id;
  425. // $compound->jumlah_asal_kompaun = $faulty->amount;
  426. $compound->dikeluarkan_ = $staff->_id;
  427. $compound->status = 'Belum Bayar';
  428. $compound->modul = '03';
  429. $compound->no_telefon = $request->tel;
  430. $compound->no_akaun_lesen = $request->lesen;
  431. $compound->bil_haiwan = $request->lesen;
  432. $compound->cpn_created = Carbon::now()->toDateTimeString();
  433. }elseif($request->jenis == 'Pelbagai_LESEN'){
  434. $compound->jenis = $request->jenis;
  435. $compound->nama = $request->namaP;
  436. $compound->identity = $request->noIc;
  437. $compound->nama_syarikat = $request->namaS;
  438. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  439. $compound->alamat = $request->alamat;
  440. $compound->no_plate = $request->no_plate;
  441. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  442. // $compound->nama_kawasan = $request->namaKawasan;
  443. // $compound->nama_taman = $request->namaTaman;
  444. // $compound->nama_jalan = $request->namaJalan;
  445. $compound->catatan = $request->catatan;
  446. $compound->latlong = $request->Latlong;
  447. // $compound->akta = $faulty->deed_law_id;
  448. // $compound->seksyen_kesalahan = $faulty->_id;
  449. // $compound->jumlah_asal_kompaun = $faulty->amount;
  450. $compound->dikeluarkan_ = $staff->_id;
  451. $compound->status = 'Belum Bayar';
  452. $compound->modul = '03';
  453. $compound->no_telefon = $request->tel;
  454. $compound->no_akaun_lesen = $request->lesen;
  455. $compound->cpn_created = Carbon::now()->toDateTimeString();
  456. }
  457. $saved = $compound->save();
  458. }
  459. else
  460. {
  461. return $this->sendResponse('', 'Kompaun ini telah dikeluarkan!');
  462. }
  463. }
  464. }
  465. if($saved){
  466. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  467. // if(!empty($compound)){
  468. dispatch(new UpdateCompoundPrice($kpd));
  469. // $tawaran = '';
  470. // if($compound->jumlah_kemaskini_kompaun != ''){
  471. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  472. // }else{
  473. // $tawaran = $compound->jumlah_asal_kompaun;
  474. // }
  475. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  476. array_push($data, array('kpd' => $kpd));
  477. // $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  478. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  479. // }
  480. }
  481. }
  482. }
  483. /*********************************************
  484. | Store a newly created notice
  485. *********************************************/
  486. public function storeNotice(Request $request)
  487. {
  488. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  489. if(empty($staff)){
  490. return $this->sendError('Invalid', 'Staff not existed');
  491. }else {
  492. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  493. if(!empty($faulty)){
  494. $data = array();
  495. $countKPD = $this->compound->withTrashed()->count();
  496. do {
  497. $countKPD = $countKPD + 1;
  498. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  499. $kpd = $countKPD;
  500. $no_siri = date('yn').'-'.$countKPD;
  501. $fileData = [
  502. 'no_siri' => $no_siri,
  503. ];
  504. if($request->jenis == 'Parkir'){
  505. $compoundData = [
  506. 'jenis' => 'Parkir',
  507. 'kpd' => $kpd,
  508. 'nama' => '-',
  509. 'identity' => '-',
  510. 'alamat' => '-',
  511. "no_plate" => strtolower($request->no_plate),
  512. "no_cukai_jalan" => $request->noCukaijalan,
  513. "jenis_kenderaan" => $request->jenisKenderaan,
  514. "model_kenderaan" => $request->modelKenderaan,
  515. "warna_kenderaan" => $request->warnakenderaan,
  516. "nama_kawasan" => $request->namaKawasan,
  517. "nama_taman" => $request->namaTaman,
  518. "nama_jalan" => $request->namaJalan,
  519. "no_parking" => $request->noParking,
  520. "catatan" => $request->catatan,
  521. "lokasi_kejadian" => '-',
  522. 'latlong' => $request->Latlong,
  523. 'jbkod' => $request->jabatan,
  524. 'akta' => $faulty->deed_law_id,
  525. 'seksyen_kesalahan' => $faulty->_id,
  526. 'jumlah_asal_kompaun' => $faulty->amount,
  527. 'jumlah_kemaskini_kompaun' => '',
  528. 'dikeluarkan' => $staff->_id,
  529. "status" => 'Belum Bayar',
  530. "amount_payment" => '',
  531. "receipt" => '',
  532. "modul" => $request->modul,
  533. "penguatkuasa" => '',
  534. "notis_created" => Carbon::now()->toDateTimeString(),
  535. ];
  536. }elseif($request->jenis == 'Pelbagai_KT'){
  537. $compoundData = [
  538. 'jenis' => $request->jenis,
  539. 'kpd' => $kpd,
  540. 'nama' => $request->namaP,
  541. 'identity' => $request->noIc,
  542. 'nama_syarikat' => $request->namaS,
  543. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  544. 'alamat' => $request->alamat,
  545. "no_plate" => $request->no_plate,
  546. "no_cukai_jalan" => $request->no_cukai_jalan,
  547. "nama_kawasan" => $request->namaKawasan,
  548. "nama_taman" => $request->namaTaman,
  549. "nama_jalan" => $request->namaJalan,
  550. "catatan" => $request->catatan,
  551. "lokasi_kejadian" => '-',
  552. 'latlong' => $request->Latlong,
  553. 'jbkod' => $request->jabatan,
  554. 'akta' => $faulty->deed_law_id,
  555. 'seksyen_kesalahan' => $faulty->_id,
  556. 'jumlah_asal_kompaun' => $faulty->amount,
  557. 'jumlah_kemaskini_kompaun' => '',
  558. 'dikeluarkan' => $staff->_id,
  559. "status" => 'Belum Bayar',
  560. "amount_payment" => '',
  561. "receipt" => '',
  562. "modul" => $request->modul,
  563. "penguatkuasa" => '',
  564. "no_telefon" => $request->tel,
  565. "no_akaun_lesen" => $request->lesen,
  566. "maklumat_tambahan" => '-',
  567. "tindakan" => $request->tindakan,
  568. "tempoh" => $request->tempoh,
  569. "notis_created" => Carbon::now()->toDateTimeString(),
  570. ];
  571. }elseif($request->jenis == 'Pelbagai_JPB'){
  572. $compoundData = [
  573. 'jenis' => $request->jenis,
  574. 'kpd' => $kpd,
  575. 'nama' => $request->namaP,
  576. 'identity' => $request->noIc,
  577. 'nama_syarikat' => $request->namaS,
  578. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  579. 'alamat' => $request->alamat,
  580. "no_plate" => $request->no_plate,
  581. "no_cukai_jalan" => $request->no_cukai_jalan,
  582. "nama_kawasan" => $request->namaKawasan,
  583. "nama_taman" => $request->namaTaman,
  584. "nama_jalan" => $request->namaJalan,
  585. "catatan" => $request->catatan,
  586. "lokasi_kejadian" => '-',
  587. 'latlong' => $request->Latlong,
  588. 'jbkod' => $request->jabatan,
  589. 'akta' => $faulty->deed_law_id,
  590. 'seksyen_kesalahan' => $faulty->_id,
  591. 'jumlah_asal_kompaun' => $faulty->amount,
  592. 'jumlah_kemaskini_kompaun' => '',
  593. 'dikeluarkan' => $staff->_id,
  594. "status" => 'Belum Bayar',
  595. "amount_payment" => '',
  596. "receipt" => '',
  597. "modul" => $request->modul,
  598. "penguatkuasa" => '',
  599. "no_telefon" => $request->tel,
  600. "no_akaun_lesen" => $request->lesen,
  601. "maklumat_tambahan" => '-',
  602. "tindakan" => $request->tindakan,
  603. "tempoh" => $request->tempoh,
  604. "notis_created" => Carbon::now()->toDateTimeString(),
  605. ];
  606. }
  607. elseif($request->jenis == 'Pelbagai_LESEN'){
  608. $compoundData = [
  609. 'jenis' => $request->jenis,
  610. 'kpd' => $kpd,
  611. 'nama' => $request->namaP,
  612. 'identity' => $request->noIc,
  613. 'nama_syarikat' => $request->namaS,
  614. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  615. 'alamat' => $request->alamat,
  616. "no_plate" => $request->no_plate,
  617. "no_cukai_jalan" => $request->no_cukai_jalan,
  618. "nama_kawasan" => $request->namaKawasan,
  619. "nama_taman" => $request->namaTaman,
  620. "nama_jalan" => $request->namaJalan,
  621. "catatan" => $request->catatan,
  622. "lokasi_kejadian" => '-',
  623. 'latlong' => $request->Latlong,
  624. 'jbkod' => $request->jabatan,
  625. 'akta' => $faulty->deed_law_id,
  626. 'seksyen_kesalahan' => $faulty->_id,
  627. 'jumlah_asal_kompaun' => $faulty->amount,
  628. 'jumlah_kemaskini_kompaun' => '',
  629. 'dikeluarkan' => $staff->_id,
  630. "status" => 'Belum Bayar',
  631. "amount_payment" => '',
  632. "receipt" => '',
  633. "modul" => $request->modul,
  634. "penguatkuasa" => '',
  635. "no_telefon" => $request->tel,
  636. "no_akaun_lesen" => $request->lesen,
  637. "maklumat_tambahan" => '-',
  638. "notis_created" => Carbon::now()->toDateTimeString(),
  639. ];
  640. }
  641. elseif($request->jenis == 'Pelbagai_PA'){
  642. $compoundData = [
  643. 'jenis' => $request->jenis,
  644. 'kpd' => $kpd,
  645. 'nama' => $request->namaP,
  646. 'identity' => $request->noIc,
  647. 'nama_syarikat' => $request->namaS,
  648. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  649. 'alamat' => $request->alamat,
  650. "no_plate" => $request->no_plate,
  651. "no_cukai_jalan" => $request->no_cukai_jalan,
  652. "nama_kawasan" => $request->namaKawasan,
  653. "nama_taman" => $request->namaTaman,
  654. "nama_jalan" => $request->namaJalan,
  655. "catatan" => $request->catatan,
  656. "lokasi_kejadian" => '-',
  657. 'latlong' => $request->Latlong,
  658. 'jbkod' => $request->jabatan,
  659. 'akta' => $faulty->deed_law_id,
  660. 'seksyen_kesalahan' => $faulty->_id,
  661. 'jumlah_asal_kompaun' => $faulty->amount,
  662. 'jumlah_kemaskini_kompaun' => '',
  663. 'dikeluarkan' => $staff->_id,
  664. "status" => 'Belum Bayar',
  665. "amount_payment" => '',
  666. "receipt" => '',
  667. "modul" => $request->modul,
  668. "penguatkuasa" => '',
  669. "no_telefon" => $request->tel,
  670. "no_akaun_lesen" => $request->lesen,
  671. "maklumat_tambahan" => '-',
  672. "bil_haiwan" => $request->bil_haiwan,
  673. "notis_created" => Carbon::now()->toDateTimeString(),
  674. ];
  675. }
  676. $file = ConfidentialFile::create($fileData);
  677. $saved = $file->compound()->create($compoundData);
  678. if($saved){
  679. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  680. // if(!empty($compound)){
  681. dispatch(new UpdateCompoundPrice($kpd));
  682. // $tawaran = '';
  683. // if($compound->jumlah_kemaskini_kompaun != ''){
  684. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  685. // }else{
  686. // $tawaran = $compound->jumlah_asal_kompaun;
  687. // }
  688. $this->dispatch(new StoreNotice($request->all(), $kpd, $staff->_id, $no_siri));
  689. array_push($data, array('kpd' => $kpd));
  690. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  691. // }
  692. }
  693. }
  694. }
  695. }
  696. /**
  697. * Store a newly created compound (parkir, KT, JPB).
  698. *
  699. * @param \Illuminate\Http\Request $request
  700. * @return \Illuminate\Http\Response
  701. */
  702. public function storeCompound(Request $request)
  703. {
  704. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  705. if(empty($staff)){
  706. return $this->sendError('Invalid', 'Staff not existed');
  707. }else {
  708. $data = array();
  709. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  710. if(!empty($faulty)){
  711. $countKPD = $this->compound->withTrashed()->count();
  712. do {
  713. $countKPD = $countKPD + 1;
  714. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  715. $kpd = $countKPD;
  716. $no_siri = date('yn').'-'.$countKPD;
  717. $fileData = [
  718. 'no_siri' => $no_siri,
  719. ];
  720. if($request->jenis == 'Parkir')
  721. {
  722. //only for compound parkir
  723. $compoundData = [
  724. 'jenis' => 'Parkir',
  725. 'kpd' => $kpd,
  726. 'nama' => '-',
  727. 'identity' => '-',
  728. 'alamat' => '-',
  729. "no_plate" => strtolower($request->no_plate),
  730. "no_cukai_jalan" => $request->noCukaijalan,
  731. "jenis_kenderaan" => $request->jenisKenderaan,
  732. "model_kenderaan" => $request->modelKenderaan,
  733. "warna_kenderaan" => $request->warnakenderaan,
  734. "nama_kawasan" => $request->namaKawasan,
  735. "nama_taman" => $request->namaTaman,
  736. "nama_jalan" => $request->namaJalan,
  737. "no_parking" => $request->noParking,
  738. "catatan" => $request->catatan,
  739. "lokasi_kejadian" => '-',
  740. 'latlong' => $request->Latlong,
  741. 'jbkod' => $request->jabatan,
  742. 'akta' => $faulty->deed_law_id,
  743. 'seksyen_kesalahan' => $faulty->_id,
  744. 'jumlah_asal_kompaun' => $faulty->amount,
  745. 'jumlah_kemaskini_kompaun' => '',
  746. 'dikeluarkan' => $staff->_id,
  747. "status" => 'Belum Bayar',
  748. "amount_payment" => '',
  749. "receipt" => '',
  750. "modul" => '03',
  751. "penguatkuasa" => '',
  752. "cpn_created" => Carbon::now()->toDateTimeString(),
  753. ];
  754. }
  755. if ($request->jenis == 'Pelbagai_KT') {
  756. $compoundData = [
  757. 'jenis' => $request->jenis,
  758. 'kpd' => $kpd,
  759. 'nama' => $request->namaP,
  760. 'identity' => $request->noIc,
  761. 'nama_syarikat' => $request->namaS,
  762. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  763. 'alamat' => $request->alamat,
  764. "no_plate" => $request->no_plate,
  765. "no_cukai_jalan" => $request->no_cukai_jalan,
  766. "nama_kawasan" => $request->namaKawasan,
  767. "nama_taman" => $request->namaTaman,
  768. "nama_jalan" => $request->namaJalan,
  769. "catatan" => $request->catatan,
  770. "lokasi_kejadian" => '-',
  771. 'latlong' => $request->Latlong,
  772. 'jbkod' => $request->jabatan,
  773. 'akta' => $faulty->deed_law_id,
  774. 'seksyen_kesalahan' => $faulty->_id,
  775. 'jumlah_asal_kompaun' => $faulty->amount,
  776. 'jumlah_kemaskini_kompaun' => '',
  777. 'dikeluarkan' => $staff->_id,
  778. "status" => 'Belum Bayar',
  779. "amount_payment" => '',
  780. "receipt" => '',
  781. "modul" => $request->modul,
  782. "penguatkuasa" => '',
  783. "no_telefon" => $request->tel,
  784. "no_akaun_lesen" => $request->lesen,
  785. "maklumat_tambahan" => '-',
  786. "tindakan" => $request->tindakan,
  787. "tempoh" => $request->tempoh,
  788. "notis_created" => Carbon::now()->toDateTimeString(),
  789. ];
  790. }
  791. elseif ($request->jenis == 'Pelbagai_JPB') {
  792. $compoundData = [
  793. 'jenis' => $request->jenis,
  794. 'kpd' => $kpd,
  795. 'nama' => $request->namaP,
  796. 'identity' => $request->noIc,
  797. 'nama_syarikat' => $request->namaS,
  798. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  799. 'alamat' => $request->alamat,
  800. "no_plate" => $request->no_plate,
  801. "no_cukai_jalan" => $request->no_cukai_jalan,
  802. "nama_kawasan" => $request->namaKawasan,
  803. "nama_taman" => $request->namaTaman,
  804. "nama_jalan" => $request->namaJalan,
  805. "catatan" => $request->catatan,
  806. "lokasi_kejadian" => '-',
  807. 'latlong' => $request->Latlong,
  808. 'jbkod' => $request->jabatan,
  809. 'akta' => $faulty->deed_law_id,
  810. 'seksyen_kesalahan' => $faulty->_id,
  811. 'jumlah_asal_kompaun' => $faulty->amount,
  812. 'jumlah_kemaskini_kompaun' => '',
  813. 'dikeluarkan' => $staff->_id,
  814. "status" => 'Belum Bayar',
  815. "amount_payment" => '',
  816. "receipt" => '',
  817. "modul" => $request->modul,
  818. "penguatkuasa" => '',
  819. "no_telefon" => $request->tel,
  820. "no_akaun_lesen" => $request->lesen,
  821. "maklumat_tambahan" => '-',
  822. "tindakan" => $request->tindakan,
  823. "tempoh" => $request->tempoh,
  824. "notis_created" => Carbon::now()->toDateTimeString(),
  825. ];
  826. }
  827. elseif ($request->jenis == 'Pelbagai_LESEN') {
  828. $compoundData = [
  829. 'jenis' => $request->jenis,
  830. 'kpd' => $kpd,
  831. 'nama' => $request->namaP,
  832. 'identity' => $request->noIc,
  833. 'nama_syarikat' => $request->namaS,
  834. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  835. 'alamat' => $request->alamat,
  836. "no_plate" => $request->no_plate,
  837. "no_cukai_jalan" => $request->no_cukai_jalan,
  838. "nama_kawasan" => $request->namaKawasan,
  839. "nama_taman" => $request->namaTaman,
  840. "nama_jalan" => $request->namaJalan,
  841. "catatan" => $request->catatan,
  842. "lokasi_kejadian" => '-',
  843. 'latlong' => $request->Latlong,
  844. 'jbkod' => $request->jabatan,
  845. 'akta' => $faulty->deed_law_id,
  846. 'seksyen_kesalahan' => $faulty->_id,
  847. 'jumlah_asal_kompaun' => $faulty->amount,
  848. 'jumlah_kemaskini_kompaun' => '',
  849. 'dikeluarkan' => $staff->_id,
  850. "status" => 'Belum Bayar',
  851. "amount_payment" => '',
  852. "receipt" => '',
  853. "modul" => $request->modul,
  854. "penguatkuasa" => '',
  855. "no_telefon" => $request->tel,
  856. "no_akaun_lesen" => $request->lesen,
  857. "maklumat_tambahan" => '-',
  858. "notis_created" => Carbon::now()->toDateTimeString(),
  859. ];
  860. }
  861. else if($request->jenis == 'Pelbagai_PA'){
  862. $compoundData = [
  863. 'jenis' => $request->jenis,
  864. 'kpd' => $kpd,
  865. 'nama' => $request->namaP,
  866. 'identity' => $request->noIc,
  867. 'nama_syarikat' => $request->namaS,
  868. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  869. 'alamat' => $request->alamat,
  870. "no_plate" => $request->no_plate,
  871. "no_cukai_jalan" => $request->no_cukai_jalan,
  872. "nama_kawasan" => $request->namaKawasan,
  873. "nama_taman" => $request->namaTaman,
  874. "nama_jalan" => $request->namaJalan,
  875. "catatan" => $request->catatan,
  876. "lokasi_kejadian" => '-',
  877. 'latlong' => $request->Latlong,
  878. 'jbkod' => $request->jabatan,
  879. 'akta' => $faulty->deed_law_id,
  880. 'seksyen_kesalahan' => $faulty->_id,
  881. 'jumlah_asal_kompaun' => $faulty->amount,
  882. 'jumlah_kemaskini_kompaun' => '',
  883. 'dikeluarkan' => $staff->_id,
  884. "status" => 'Belum Bayar',
  885. "amount_payment" => '',
  886. "receipt" => '',
  887. "modul" => $request->modul,
  888. "penguatkuasa" => '',
  889. "no_telefon" => $request->tel,
  890. "no_akaun_lesen" => $request->lesen,
  891. "maklumat_tambahan" => '-',
  892. "bil_haiwan" => $request->bil_haiwan,
  893. "notis_created" => Carbon::now()->toDateTimeString(),
  894. ];
  895. }
  896. $file = ConfidentialFile::create($fileData);
  897. $saved = $file->compound()->create($compoundData);
  898. }
  899. if($saved){
  900. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  901. // if(!empty($compound)){
  902. dispatch(new UpdateCompoundPrice($kpd));
  903. // $tawaran = '';
  904. // if($compound->jumlah_kemaskini_kompaun != ''){
  905. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  906. // }else{
  907. // $tawaran = $compound->jumlah_asal_kompaun;
  908. // }
  909. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  910. array_push($data, array('kpd' => $kpd));
  911. // $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  912. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  913. // }
  914. }
  915. }
  916. }
  917. /**
  918. * Display the specified resource.
  919. *
  920. * @param int $id
  921. * @return \Illuminate\Http\Response
  922. */
  923. public function show($id)
  924. {
  925. //
  926. }
  927. /**
  928. * Show the form for editing the specified resource.
  929. *
  930. * @param int $id
  931. * @return \Illuminate\Http\Response
  932. */
  933. public function edit($id)
  934. {
  935. //
  936. }
  937. /**
  938. * Update the specified resource in storage.
  939. *
  940. * @param \Illuminate\Http\Request $request
  941. * @param int $id
  942. * @return \Illuminate\Http\Response
  943. */
  944. public function update(Request $request, $id)
  945. {
  946. //
  947. }
  948. public function updateStatusPaymentViaDashboard(Request $request)
  949. {
  950. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  951. $staff = StaffDetail::find($request->current_id);
  952. if(!empty($compound) && !empty($staff)){
  953. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  954. if($compound->status != $request->status){
  955. $compound->status = $request->status;
  956. $compound->catatan_dari_admin = $request->remark;
  957. $compound->amount_payment = $request->amount;
  958. $compound->update_by = $request->current_id;
  959. $saved = $compound->save();
  960. if($saved){
  961. $gDate = $compound->created_at->format('F Y');
  962. $historyData = [
  963. 'tarikh_kumpulan' => $gDate,
  964. ];
  965. $subHistory = [
  966. 'no_siri' => $compound->ConfidentialFile->no_siri,
  967. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  968. '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>",
  969. ];
  970. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  971. if(!empty($groupByDate)){
  972. $groupByDate->subhistory()->create($subHistory);
  973. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  974. }else{
  975. $history = History::create($historyData);
  976. $history->subhistory()->create($subHistory);
  977. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  978. }
  979. if($request->status == "Berbayar"){
  980. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  981. }else{
  982. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  983. }
  984. }else{
  985. $response = [
  986. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  987. ];
  988. return response()->json($response, 200);
  989. }
  990. }else{
  991. if($request->remark != ''){
  992. $compound->catatan_dari_admin = $request->remark;
  993. $compound->update_by = $request->current_id;
  994. $compound->save();
  995. $saved = $compound->save();
  996. if($saved){
  997. $gDate = $compound->created_at->format('F Y');
  998. $historyData = [
  999. 'tarikh_kumpulan' => $gDate,
  1000. ];
  1001. $subHistory = [
  1002. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1003. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1004. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1005. ];
  1006. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1007. if(!empty($groupByDate)){
  1008. $groupByDate->subhistory()->create($subHistory);
  1009. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1010. }else{
  1011. $history = History::create($historyData);
  1012. $history->subhistory()->create($subHistory);
  1013. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1014. }
  1015. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1016. }else{
  1017. $response = [
  1018. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1019. ];
  1020. return response()->json($response, 200);
  1021. }
  1022. }else{
  1023. $response = [
  1024. 'success' => false, 'message' => 'Tiada kemaskini!',
  1025. ];
  1026. return response()->json($response, 200);
  1027. }
  1028. }
  1029. }else{
  1030. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1031. $compound->status = $request->status;
  1032. $compound->catatan_dari_admin = $request->remark;
  1033. $compound->amount_payment = $request->amount;
  1034. $compound->update_by = $request->current_id;
  1035. $saved = $compound->save();
  1036. if($saved){
  1037. $gDate = $compound->created_at->format('F Y');
  1038. $historyData = [
  1039. 'tarikh_kumpulan' => $gDate,
  1040. ];
  1041. $subHistory = [
  1042. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1043. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1044. '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>",
  1045. ];
  1046. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1047. if(!empty($groupByDate)){
  1048. $groupByDate->subhistory()->create($subHistory);
  1049. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1050. }else{
  1051. $history = History::create($historyData);
  1052. $history->subhistory()->create($subHistory);
  1053. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1054. }
  1055. if($request->status == "Berbayar"){
  1056. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1057. }else{
  1058. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1059. }
  1060. }else{
  1061. $response = [
  1062. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1063. ];
  1064. return response()->json($response, 200);
  1065. }
  1066. }else{
  1067. if($request->remark != ''){
  1068. $compound->catatan_dari_admin = $request->remark;
  1069. $compound->update_by = $request->current_id;
  1070. $compound->save();
  1071. $saved = $compound->save();
  1072. if($saved){
  1073. $gDate = $compound->created_at->format('F Y');
  1074. $historyData = [
  1075. 'tarikh_kumpulan' => $gDate,
  1076. ];
  1077. $subHistory = [
  1078. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1079. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1080. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1081. ];
  1082. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1083. if(!empty($groupByDate)){
  1084. $groupByDate->subhistory()->create($subHistory);
  1085. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1086. }else{
  1087. $history = History::create($historyData);
  1088. $history->subhistory()->create($subHistory);
  1089. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1090. }
  1091. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1092. }else{
  1093. $response = [
  1094. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1095. ];
  1096. return response()->json($response, 200);
  1097. }
  1098. }else{
  1099. $response = [
  1100. 'success' => false, 'message' => 'Tiada kemaskini!',
  1101. ];
  1102. return response()->json($response, 200);
  1103. }
  1104. }
  1105. }
  1106. }else{
  1107. $response = [
  1108. 'success' => false,
  1109. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  1110. ];
  1111. return response()->json($response, 200);
  1112. }
  1113. }
  1114. /**
  1115. * Remove the specified resource from storage.
  1116. *
  1117. * @param int $id
  1118. * @return \Illuminate\Http\Response
  1119. */
  1120. public function destroy($id)
  1121. {
  1122. //
  1123. }
  1124. }