Dashboard sipadu mbip
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CompoundResourceController.php 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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\UpdateCompoundPrice;
  19. use App\Http\Resources\CompoundResource;
  20. class CompoundResourceController extends BaseController
  21. {
  22. /**
  23. * @var ServiceCategory
  24. */
  25. protected $compound;
  26. /**
  27. * ServiceController constructor.
  28. *
  29. * @param ServiceCategory $ServiceCategory
  30. */
  31. public function __construct(Compound $compound)
  32. {
  33. $this->compound = $compound;
  34. }
  35. /**
  36. * Display a listing of the resource.
  37. *
  38. * @return \Illuminate\Http\Response
  39. */
  40. private function searchCompoundAll($jenis,$modul,$status,$start_date,$end_date){
  41. $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
  42. $start = $dateS->copy()->startOfDay();
  43. if($end_date != ''){
  44. $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
  45. $end = $dateE->copy()->endOfDay();
  46. }else{
  47. $end = $dateS->copy()->endOfDay();
  48. }
  49. if($modul == '06-07'){
  50. $compound = Compound::where(function($q){
  51. $q->where(function($query){
  52. $query->where('modul', '06')->orWhere('modul','07');
  53. });
  54. })->where('status', $status)->where('jenis', $jenis)->whereBetween('created_at', array($start, $end));
  55. }else if($status != 'Berbayar'){
  56. if($status == 'All'){
  57. $compound = Compound::where('modul', $modul)->where('status','!=','Berbayar')->where('jenis', $jenis)
  58. ->whereBetween('created_at', array($start, $end));
  59. }else{
  60. $compound = Compound::where('modul', $modul)->where('status', $status)->where('jenis', $jenis)
  61. ->whereBetween('created_at', array($start, $end));
  62. }
  63. // $compound = Compound::where('modul', $modul)->where('status', $status)->where('jenis', $jenis)
  64. // ->whereBetween('created_at', array($start, $end));
  65. }else{
  66. $compound = Compound::where('status', $status)->where('jenis', $jenis)
  67. ->whereBetween('created_at', array($start, $end));
  68. }
  69. return $compound;
  70. }
  71. private function searchCompoundAllWithoutDate($jenis,$modul,$status){
  72. if($modul == '06-07'){
  73. $compound = Compound::where(function($q){
  74. $q->where(function($query){
  75. $query->where('modul', '06')->orWhere('modul','07');
  76. });
  77. })->where('status', $status)->where('jenis', $jenis);
  78. }else if($status != 'Berbayar'){
  79. if($status == 'All'){
  80. $compound = Compound::where('modul', $modul)->where('status','!=','Berbayar')->where('jenis', $jenis);
  81. }else{
  82. $compound = Compound::where('modul', $modul)->where('status', $status)->where('jenis', $jenis);
  83. }
  84. }else{
  85. $compound = Compound::where('status', $status)->where('jenis', $jenis);
  86. }
  87. return $compound;
  88. }
  89. private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date){
  90. if(!empty($start_date)){
  91. $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date);
  92. }else{
  93. $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status);
  94. }
  95. if($enforcer == 'All'){
  96. return $compound;
  97. }else {
  98. $compound = $compound->where('dikeluarkan', $enforcer);
  99. return $compound;
  100. }
  101. }
  102. private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date){
  103. $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date);
  104. if($faulty == 'All'){
  105. return $compound;
  106. }else {
  107. $compound = $compound->where('seksyen_kesalahan', $faulty);
  108. return $compound;
  109. }
  110. }
  111. public function index(Request $request)
  112. {
  113. //
  114. $per_page = $request->per_page;
  115. $kpd = $request->kpd;
  116. $modul = $request->modul;
  117. $status = $request->status;
  118. $jenis = $request->type;
  119. $start_date = $request->start_date;
  120. $end_date = $request->end_date;
  121. $enforcer = $request->enforcer;
  122. $faulty = $request->faulty;
  123. $plate_no = strtolower($request->plate_no);
  124. $company_no = strtolower($request->company_no);
  125. $nric = $request->nric;
  126. $nested_data = array();
  127. if(!empty($plate_no)) {
  128. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
  129. $compound = $compound->where('no_plate',$plate_no)->orderBy('created_at','ASC')->get();
  130. }else if(!empty($kpd)){
  131. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
  132. $compound = $compound->where('kpd',$kpd)->orderBy('created_at','ASC')->get();
  133. }else if(!empty($company_no)){
  134. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
  135. $compound = $compound->where('no_daftar_syarikat',$company_no)->orderBy('created_at','ASC')->get();
  136. }else if(!empty($nric)){
  137. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
  138. $compound = $compound->where('identity',$nric)->orderBy('created_at','ASC')->get();
  139. }else{
  140. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
  141. $compound = $compound->orderBy('created_at','ASC')->get();
  142. }
  143. // return $compound;
  144. return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
  145. ->addColumn('index', function($row) {
  146. $curr = Carbon::now();
  147. $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
  148. if($curr->diffInDays($dtC) <= 3){
  149. $html = 'New';
  150. }else{ $html = ''; }
  151. return $html;
  152. })->rawColumns(['index'])->make(true);
  153. }
  154. /**
  155. * Show the form for creating a new resource.
  156. *
  157. * @return \Illuminate\Http\Response
  158. */
  159. public function create()
  160. {
  161. //
  162. }
  163. /**
  164. * Store a newly created resource in storage.
  165. *
  166. * @param \Illuminate\Http\Request $request
  167. * @return \Illuminate\Http\Response
  168. */
  169. public function store(Request $request)
  170. {
  171. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  172. if(empty($staff)){
  173. return $this->sendError('Invalid', 'Staff not existed');
  174. }else {
  175. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  176. if(!empty($faulty)){
  177. $data = array();
  178. $countKPD = $this->compound->withTrashed()->count();
  179. do {
  180. $countKPD = $countKPD + 1;
  181. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  182. $kpd = 'KP' . $countKPD;
  183. $no_siri = date('yn').'-'.$countKPD;
  184. $fileData = [
  185. 'no_siri' => $no_siri,
  186. ];
  187. if($request->jenis != 'Pelbagai'){
  188. $compoundData = [
  189. 'jenis' => 'Parkir',
  190. 'kpd' => $kpd,
  191. 'nama' => '-',
  192. 'identity' => '-',
  193. 'alamat' => '-',
  194. "no_plate" => strtolower($request->no_plate),
  195. "no_cukai_jalan" => $request->noCukaijalan,
  196. "jenis_kenderaan" => $request->jenisKenderaan,
  197. "model_kenderaan" => $request->modelKenderaan,
  198. "warna_kenderaan" => $request->warnakenderaan,
  199. "nama_kawasan" => $request->namaKawasan,
  200. "nama_taman" => $request->namaTaman,
  201. "nama_jalan" => $request->namaJalan,
  202. "no_parking" => $request->noParking,
  203. "catatan" => $request->catatan,
  204. "lokasi_kejadian" => '-',
  205. 'latlong' => $request->Latlong,
  206. 'jbkod' => $request->jabatan,
  207. 'akta' => $faulty->deed_law_id,
  208. 'seksyen_kesalahan' => $faulty->_id,
  209. 'jumlah_asal_kompaun' => $faulty->amount,
  210. 'jumlah_kemaskini_kompaun' => '',
  211. 'dikeluarkan' => $staff->_id,
  212. "status" => 'Belum Bayar',
  213. "amount_payment" => '',
  214. "receipt" => '',
  215. "modul" => '03',
  216. "penguatkuasa" => '',
  217. ];
  218. }else{
  219. $compoundData = [
  220. 'jenis' => 'Pelbagai',
  221. 'kpd' => $kpd,
  222. 'nama' => $request->namaP,
  223. 'identity' => $request->noIc,
  224. 'nama_syarikat' => $request->namaS,
  225. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  226. 'alamat' => $request->alamat,
  227. "no_plate" => $request->no_plate,
  228. "no_cukai_jalan" => $request->no_cukai_jalan,
  229. "catatan" => $request->catatan,
  230. "lokasi_kejadian" => '-',
  231. 'latlong' => $request->Latlong,
  232. 'jbkod' => $request->jabatan,
  233. 'akta' => $faulty->deed_law_id,
  234. 'seksyen_kesalahan' => $faulty->_id,
  235. 'jumlah_asal_kompaun' => $faulty->amount,
  236. 'jumlah_kemaskini_kompaun' => '',
  237. 'dikeluarkan' => $staff->_id,
  238. "status" => 'Belum Bayar',
  239. "amount_payment" => '',
  240. "receipt" => '',
  241. "modul" => '03',
  242. "penguatkuasa" => '',
  243. "no_telefon" => $request->tel,
  244. "no_akaun_lesen" => $request->lesen,
  245. "maklumat_tambahan" => '-',
  246. ];
  247. }
  248. $file = ConfidentialFile::create($fileData);
  249. $saved = $file->compound()->create($compoundData);
  250. if($saved){
  251. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  252. // if(!empty($compound)){
  253. dispatch(new UpdateCompoundPrice($kpd));
  254. // $tawaran = '';
  255. // if($compound->jumlah_kemaskini_kompaun != ''){
  256. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  257. // }else{
  258. // $tawaran = $compound->jumlah_asal_kompaun;
  259. // }
  260. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  261. array_push($data, array('kpd' => $kpd));
  262. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  263. // }
  264. }
  265. }
  266. }
  267. }
  268. public function storeNotice(Request $request)
  269. {
  270. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  271. if(empty($staff)){
  272. return $this->sendError('Invalid', 'Staff not existed');
  273. }else {
  274. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  275. if(!empty($faulty)){
  276. $data = array();
  277. $countKPD = $this->compound->withTrashed()->count();
  278. do {
  279. $countKPD = $countKPD + 1;
  280. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  281. $kpd = 'KP' . $countKPD;
  282. $no_siri = date('yn').'-'.$countKPD;
  283. $fileData = [
  284. 'no_siri' => $no_siri,
  285. ];
  286. if($request->jenis != 'Pelbagai'){
  287. $compoundData = [
  288. 'jenis' => 'Parkir',
  289. 'kpd' => $kpd,
  290. 'nama' => '-',
  291. 'identity' => '-',
  292. 'alamat' => '-',
  293. "no_plate" => strtolower($request->no_plate),
  294. "no_cukai_jalan" => $request->noCukaijalan,
  295. "jenis_kenderaan" => $request->jenisKenderaan,
  296. "model_kenderaan" => $request->modelKenderaan,
  297. "warna_kenderaan" => $request->warnakenderaan,
  298. "nama_kawasan" => $request->namaKawasan,
  299. "nama_taman" => $request->namaTaman,
  300. "nama_jalan" => $request->namaJalan,
  301. "no_parking" => $request->noParking,
  302. "catatan" => $request->catatan,
  303. "lokasi_kejadian" => '-',
  304. 'latlong' => $request->Latlong,
  305. 'jbkod' => $request->jabatan,
  306. 'akta' => $faulty->deed_law_id,
  307. 'seksyen_kesalahan' => $faulty->_id,
  308. 'jumlah_asal_kompaun' => $faulty->amount,
  309. 'jumlah_kemaskini_kompaun' => '',
  310. 'dikeluarkan' => $staff->_id,
  311. "status" => 'Belum Bayar',
  312. "amount_payment" => '',
  313. "receipt" => '',
  314. "modul" => '05',
  315. "penguatkuasa" => '',
  316. ];
  317. }else{
  318. $compoundData = [
  319. 'jenis' => 'Pelbagai',
  320. 'kpd' => $kpd,
  321. 'nama' => $request->namaP,
  322. 'identity' => $request->noIc,
  323. 'nama_syarikat' => $request->namaS,
  324. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  325. 'alamat' => $request->alamat,
  326. "no_plate" => $request->no_plate,
  327. "no_cukai_jalan" => $request->no_cukai_jalan,
  328. "catatan" => $request->catatan,
  329. "lokasi_kejadian" => '-',
  330. 'latlong' => $request->Latlong,
  331. 'jbkod' => $request->jabatan,
  332. 'akta' => $faulty->deed_law_id,
  333. 'seksyen_kesalahan' => $faulty->_id,
  334. 'jumlah_asal_kompaun' => $faulty->amount,
  335. 'jumlah_kemaskini_kompaun' => '',
  336. 'dikeluarkan' => $staff->_id,
  337. "status" => 'Belum Bayar',
  338. "amount_payment" => '',
  339. "receipt" => '',
  340. "modul" => '05',
  341. "penguatkuasa" => '',
  342. "no_telefon" => $request->tel,
  343. "no_akaun_lesen" => $request->lesen,
  344. "maklumat_tambahan" => '-',
  345. ];
  346. }
  347. $file = ConfidentialFile::create($fileData);
  348. $saved = $file->compound()->create($compoundData);
  349. if($saved){
  350. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  351. // if(!empty($compound)){
  352. dispatch(new UpdateCompoundPrice($kpd));
  353. // $tawaran = '';
  354. // if($compound->jumlah_kemaskini_kompaun != ''){
  355. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  356. // }else{
  357. // $tawaran = $compound->jumlah_asal_kompaun;
  358. // }
  359. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  360. array_push($data, array('kpd' => $kpd));
  361. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  362. // }
  363. }
  364. }
  365. }
  366. }
  367. /**
  368. * Display the specified resource.
  369. *
  370. * @param int $id
  371. * @return \Illuminate\Http\Response
  372. */
  373. public function show($id)
  374. {
  375. //
  376. }
  377. /**
  378. * Show the form for editing the specified resource.
  379. *
  380. * @param int $id
  381. * @return \Illuminate\Http\Response
  382. */
  383. public function edit($id)
  384. {
  385. //
  386. }
  387. /**
  388. * Update the specified resource in storage.
  389. *
  390. * @param \Illuminate\Http\Request $request
  391. * @param int $id
  392. * @return \Illuminate\Http\Response
  393. */
  394. public function update(Request $request, $id)
  395. {
  396. //
  397. }
  398. public function updateStatusPaymentViaDashboard(Request $request)
  399. {
  400. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  401. $staff = StaffDetail::find($request->current_id);
  402. if(!empty($compound) && !empty($staff)){
  403. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  404. if($compound->status != $request->status){
  405. $compound->status = $request->status;
  406. $compound->catatan_dari_admin = $request->remark;
  407. $compound->amount_payment = $request->amount;
  408. $compound->update_by = $request->current_id;
  409. $saved = $compound->save();
  410. if($saved){
  411. $gDate = $compound->created_at->format('F Y');
  412. $historyData = [
  413. 'tarikh_kumpulan' => $gDate,
  414. ];
  415. $subHistory = [
  416. 'no_siri' => $compound->ConfidentialFile->no_siri,
  417. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  418. '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>",
  419. ];
  420. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  421. if(!empty($groupByDate)){
  422. $groupByDate->subhistory()->create($subHistory);
  423. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  424. }else{
  425. $history = History::create($historyData);
  426. $history->subhistory()->create($subHistory);
  427. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  428. }
  429. if($request->status == "Berbayar"){
  430. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  431. }else{
  432. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  433. }
  434. }else{
  435. $response = [
  436. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  437. ];
  438. return response()->json($response, 200);
  439. }
  440. }else{
  441. if($request->remark != ''){
  442. $compound->catatan_dari_admin = $request->remark;
  443. $compound->update_by = $request->current_id;
  444. $compound->save();
  445. $saved = $compound->save();
  446. if($saved){
  447. $gDate = $compound->created_at->format('F Y');
  448. $historyData = [
  449. 'tarikh_kumpulan' => $gDate,
  450. ];
  451. $subHistory = [
  452. 'no_siri' => $compound->ConfidentialFile->no_siri,
  453. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  454. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  455. ];
  456. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  457. if(!empty($groupByDate)){
  458. $groupByDate->subhistory()->create($subHistory);
  459. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  460. }else{
  461. $history = History::create($historyData);
  462. $history->subhistory()->create($subHistory);
  463. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  464. }
  465. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  466. }else{
  467. $response = [
  468. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  469. ];
  470. return response()->json($response, 200);
  471. }
  472. }else{
  473. $response = [
  474. 'success' => false, 'message' => 'Tiada kemaskini!',
  475. ];
  476. return response()->json($response, 200);
  477. }
  478. }
  479. }else{
  480. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  481. $compound->status = $request->status;
  482. $compound->catatan_dari_admin = $request->remark;
  483. $compound->amount_payment = $request->amount;
  484. $compound->update_by = $request->current_id;
  485. $saved = $compound->save();
  486. if($saved){
  487. $gDate = $compound->created_at->format('F Y');
  488. $historyData = [
  489. 'tarikh_kumpulan' => $gDate,
  490. ];
  491. $subHistory = [
  492. 'no_siri' => $compound->ConfidentialFile->no_siri,
  493. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  494. '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>",
  495. ];
  496. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  497. if(!empty($groupByDate)){
  498. $groupByDate->subhistory()->create($subHistory);
  499. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  500. }else{
  501. $history = History::create($historyData);
  502. $history->subhistory()->create($subHistory);
  503. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  504. }
  505. if($request->status == "Berbayar"){
  506. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  507. }else{
  508. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  509. }
  510. }else{
  511. $response = [
  512. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  513. ];
  514. return response()->json($response, 200);
  515. }
  516. }else{
  517. if($request->remark != ''){
  518. $compound->catatan_dari_admin = $request->remark;
  519. $compound->update_by = $request->current_id;
  520. $compound->save();
  521. $saved = $compound->save();
  522. if($saved){
  523. $gDate = $compound->created_at->format('F Y');
  524. $historyData = [
  525. 'tarikh_kumpulan' => $gDate,
  526. ];
  527. $subHistory = [
  528. 'no_siri' => $compound->ConfidentialFile->no_siri,
  529. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  530. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  531. ];
  532. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  533. if(!empty($groupByDate)){
  534. $groupByDate->subhistory()->create($subHistory);
  535. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  536. }else{
  537. $history = History::create($historyData);
  538. $history->subhistory()->create($subHistory);
  539. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  540. }
  541. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  542. }else{
  543. $response = [
  544. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  545. ];
  546. return response()->json($response, 200);
  547. }
  548. }else{
  549. $response = [
  550. 'success' => false, 'message' => 'Tiada kemaskini!',
  551. ];
  552. return response()->json($response, 200);
  553. }
  554. }
  555. }
  556. }else{
  557. $response = [
  558. 'success' => false,
  559. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  560. ];
  561. return response()->json($response, 200);
  562. }
  563. }
  564. /**
  565. * Remove the specified resource from storage.
  566. *
  567. * @param int $id
  568. * @return \Illuminate\Http\Response
  569. */
  570. public function destroy($id)
  571. {
  572. //
  573. }
  574. }