Dashboard sipadu mbip
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

CompoundResourceController.php 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  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 == 'Parkir'){
  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. }elseif($request->jenis == 'Pelbagai_KT'){
  219. $compoundData = [
  220. 'jenis' => $request->jenis,
  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. }elseif($request->jenis == 'Pelbagai_JPB'){
  248. $compoundData = [
  249. 'jenis' => $request->jenis,
  250. 'kpd' => $kpd,
  251. 'nama' => $request->namaP,
  252. 'identity' => $request->noIc,
  253. 'nama_syarikat' => $request->namaS,
  254. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  255. 'alamat' => $request->alamat,
  256. "no_plate" => $request->no_plate,
  257. "no_cukai_jalan" => $request->no_cukai_jalan,
  258. "catatan" => $request->catatan,
  259. "lokasi_kejadian" => '-',
  260. 'latlong' => $request->Latlong,
  261. 'jbkod' => $request->jabatan,
  262. 'akta' => $faulty->deed_law_id,
  263. 'seksyen_kesalahan' => $faulty->_id,
  264. 'jumlah_asal_kompaun' => $faulty->amount,
  265. 'jumlah_kemaskini_kompaun' => '',
  266. 'dikeluarkan' => $staff->_id,
  267. "status" => 'Belum Bayar',
  268. "amount_payment" => '',
  269. "receipt" => '',
  270. "modul" => '03',
  271. "penguatkuasa" => '',
  272. "no_telefon" => $request->tel,
  273. "no_akaun_lesen" => $request->lesen,
  274. "maklumat_tambahan" => '-',
  275. ];
  276. }
  277. $file = ConfidentialFile::create($fileData);
  278. $saved = $file->compound()->create($compoundData);
  279. if($saved){
  280. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  281. // if(!empty($compound)){
  282. dispatch(new UpdateCompoundPrice($kpd));
  283. // $tawaran = '';
  284. // if($compound->jumlah_kemaskini_kompaun != ''){
  285. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  286. // }else{
  287. // $tawaran = $compound->jumlah_asal_kompaun;
  288. // }
  289. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  290. array_push($data, array('kpd' => $kpd));
  291. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  292. // }
  293. }
  294. }
  295. }
  296. }
  297. public function storeNotice(Request $request)
  298. {
  299. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  300. if(empty($staff)){
  301. return $this->sendError('Invalid', 'Staff not existed');
  302. }else {
  303. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  304. if(!empty($faulty)){
  305. $data = array();
  306. $countKPD = $this->compound->withTrashed()->count();
  307. do {
  308. $countKPD = $countKPD + 1;
  309. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  310. $kpd = 'KP' . $countKPD;
  311. $no_siri = date('yn').'-'.$countKPD;
  312. $fileData = [
  313. 'no_siri' => $no_siri,
  314. ];
  315. if($request->jenis == 'Parkir'){
  316. $compoundData = [
  317. 'jenis' => 'Parkir',
  318. 'kpd' => $kpd,
  319. 'nama' => '-',
  320. 'identity' => '-',
  321. 'alamat' => '-',
  322. "no_plate" => strtolower($request->no_plate),
  323. "no_cukai_jalan" => $request->noCukaijalan,
  324. "jenis_kenderaan" => $request->jenisKenderaan,
  325. "model_kenderaan" => $request->modelKenderaan,
  326. "warna_kenderaan" => $request->warnakenderaan,
  327. "nama_kawasan" => $request->namaKawasan,
  328. "nama_taman" => $request->namaTaman,
  329. "nama_jalan" => $request->namaJalan,
  330. "no_parking" => $request->noParking,
  331. "catatan" => $request->catatan,
  332. "lokasi_kejadian" => '-',
  333. 'latlong' => $request->Latlong,
  334. 'jbkod' => $request->jabatan,
  335. 'akta' => $faulty->deed_law_id,
  336. 'seksyen_kesalahan' => $faulty->_id,
  337. 'jumlah_asal_kompaun' => $faulty->amount,
  338. 'jumlah_kemaskini_kompaun' => '',
  339. 'dikeluarkan' => $staff->_id,
  340. "status" => 'Belum Bayar',
  341. "amount_payment" => '',
  342. "receipt" => '',
  343. "modul" => '05',
  344. "penguatkuasa" => '',
  345. ];
  346. }elseif($request->jenis == 'Pelbagai_KT'){
  347. $compoundData = [
  348. 'jenis' => $request->jenis,
  349. 'kpd' => $kpd,
  350. 'nama' => $request->namaP,
  351. 'identity' => $request->noIc,
  352. 'nama_syarikat' => $request->namaS,
  353. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  354. 'alamat' => $request->alamat,
  355. "no_plate" => $request->no_plate,
  356. "no_cukai_jalan" => $request->no_cukai_jalan,
  357. "catatan" => $request->catatan,
  358. "lokasi_kejadian" => '-',
  359. 'latlong' => $request->Latlong,
  360. 'jbkod' => $request->jabatan,
  361. 'akta' => $faulty->deed_law_id,
  362. 'seksyen_kesalahan' => $faulty->_id,
  363. 'jumlah_asal_kompaun' => $faulty->amount,
  364. 'jumlah_kemaskini_kompaun' => '',
  365. 'dikeluarkan' => $staff->_id,
  366. "status" => 'Belum Bayar',
  367. "amount_payment" => '',
  368. "receipt" => '',
  369. "modul" => '05',
  370. "penguatkuasa" => '',
  371. "no_telefon" => $request->tel,
  372. "no_akaun_lesen" => $request->lesen,
  373. "maklumat_tambahan" => '-',
  374. ];
  375. }elseif($request->jenis == 'Pelbagai_JPB'){
  376. $compoundData = [
  377. 'jenis' => $request->jenis,
  378. 'kpd' => $kpd,
  379. 'nama' => $request->namaP,
  380. 'identity' => $request->noIc,
  381. 'nama_syarikat' => $request->namaS,
  382. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  383. 'alamat' => $request->alamat,
  384. "no_plate" => $request->no_plate,
  385. "no_cukai_jalan" => $request->no_cukai_jalan,
  386. "catatan" => $request->catatan,
  387. "lokasi_kejadian" => '-',
  388. 'latlong' => $request->Latlong,
  389. 'jbkod' => $request->jabatan,
  390. 'akta' => $faulty->deed_law_id,
  391. 'seksyen_kesalahan' => $faulty->_id,
  392. 'jumlah_asal_kompaun' => $faulty->amount,
  393. 'jumlah_kemaskini_kompaun' => '',
  394. 'dikeluarkan' => $staff->_id,
  395. "status" => 'Belum Bayar',
  396. "amount_payment" => '',
  397. "receipt" => '',
  398. "modul" => '05',
  399. "penguatkuasa" => '',
  400. "no_telefon" => $request->tel,
  401. "no_akaun_lesen" => $request->lesen,
  402. "maklumat_tambahan" => '-',
  403. ];
  404. }
  405. elseif($request->jenis == 'Lesen'){
  406. $compoundData = [
  407. 'jenis' => $request->jenis,
  408. 'kpd' => $kpd,
  409. 'nama' => $request->namaP,
  410. 'identity' => $request->noIc,
  411. 'nama_syarikat' => $request->namaS,
  412. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  413. 'alamat' => $request->alamat,
  414. "no_plate" => $request->no_plate,
  415. "no_cukai_jalan" => $request->no_cukai_jalan,
  416. "catatan" => $request->catatan,
  417. "lokasi_kejadian" => '-',
  418. 'latlong' => $request->Latlong,
  419. 'jbkod' => $request->jabatan,
  420. 'akta' => $faulty->deed_law_id,
  421. 'seksyen_kesalahan' => $faulty->_id,
  422. 'jumlah_asal_kompaun' => $faulty->amount,
  423. 'jumlah_kemaskini_kompaun' => '',
  424. 'dikeluarkan' => $staff->_id,
  425. "status" => 'Belum Bayar',
  426. "amount_payment" => '',
  427. "receipt" => '',
  428. "modul" => '05',
  429. "penguatkuasa" => '',
  430. "no_telefon" => $request->tel,
  431. "no_akaun_lesen" => $request->lesen,
  432. "bil_haiwan" => $request->bil_haiwan,
  433. ];
  434. }
  435. $file = ConfidentialFile::create($fileData);
  436. $saved = $file->compound()->create($compoundData);
  437. if($saved){
  438. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  439. // if(!empty($compound)){
  440. dispatch(new UpdateCompoundPrice($kpd));
  441. // $tawaran = '';
  442. // if($compound->jumlah_kemaskini_kompaun != ''){
  443. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  444. // }else{
  445. // $tawaran = $compound->jumlah_asal_kompaun;
  446. // }
  447. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  448. array_push($data, array('kpd' => $kpd));
  449. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  450. // }
  451. }
  452. }
  453. }
  454. }
  455. /**
  456. * Display the specified resource.
  457. *
  458. * @param int $id
  459. * @return \Illuminate\Http\Response
  460. */
  461. public function show($id)
  462. {
  463. //
  464. }
  465. /**
  466. * Show the form for editing the specified resource.
  467. *
  468. * @param int $id
  469. * @return \Illuminate\Http\Response
  470. */
  471. public function edit($id)
  472. {
  473. //
  474. }
  475. /**
  476. * Update the specified resource in storage.
  477. *
  478. * @param \Illuminate\Http\Request $request
  479. * @param int $id
  480. * @return \Illuminate\Http\Response
  481. */
  482. public function update(Request $request, $id)
  483. {
  484. //
  485. }
  486. public function updateStatusPaymentViaDashboard(Request $request)
  487. {
  488. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  489. $staff = StaffDetail::find($request->current_id);
  490. if(!empty($compound) && !empty($staff)){
  491. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  492. if($compound->status != $request->status){
  493. $compound->status = $request->status;
  494. $compound->catatan_dari_admin = $request->remark;
  495. $compound->amount_payment = $request->amount;
  496. $compound->update_by = $request->current_id;
  497. $saved = $compound->save();
  498. if($saved){
  499. $gDate = $compound->created_at->format('F Y');
  500. $historyData = [
  501. 'tarikh_kumpulan' => $gDate,
  502. ];
  503. $subHistory = [
  504. 'no_siri' => $compound->ConfidentialFile->no_siri,
  505. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  506. '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>",
  507. ];
  508. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  509. if(!empty($groupByDate)){
  510. $groupByDate->subhistory()->create($subHistory);
  511. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  512. }else{
  513. $history = History::create($historyData);
  514. $history->subhistory()->create($subHistory);
  515. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  516. }
  517. if($request->status == "Berbayar"){
  518. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  519. }else{
  520. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  521. }
  522. }else{
  523. $response = [
  524. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  525. ];
  526. return response()->json($response, 200);
  527. }
  528. }else{
  529. if($request->remark != ''){
  530. $compound->catatan_dari_admin = $request->remark;
  531. $compound->update_by = $request->current_id;
  532. $compound->save();
  533. $saved = $compound->save();
  534. if($saved){
  535. $gDate = $compound->created_at->format('F Y');
  536. $historyData = [
  537. 'tarikh_kumpulan' => $gDate,
  538. ];
  539. $subHistory = [
  540. 'no_siri' => $compound->ConfidentialFile->no_siri,
  541. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  542. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  543. ];
  544. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  545. if(!empty($groupByDate)){
  546. $groupByDate->subhistory()->create($subHistory);
  547. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  548. }else{
  549. $history = History::create($historyData);
  550. $history->subhistory()->create($subHistory);
  551. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  552. }
  553. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  554. }else{
  555. $response = [
  556. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  557. ];
  558. return response()->json($response, 200);
  559. }
  560. }else{
  561. $response = [
  562. 'success' => false, 'message' => 'Tiada kemaskini!',
  563. ];
  564. return response()->json($response, 200);
  565. }
  566. }
  567. }else{
  568. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  569. $compound->status = $request->status;
  570. $compound->catatan_dari_admin = $request->remark;
  571. $compound->amount_payment = $request->amount;
  572. $compound->update_by = $request->current_id;
  573. $saved = $compound->save();
  574. if($saved){
  575. $gDate = $compound->created_at->format('F Y');
  576. $historyData = [
  577. 'tarikh_kumpulan' => $gDate,
  578. ];
  579. $subHistory = [
  580. 'no_siri' => $compound->ConfidentialFile->no_siri,
  581. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  582. '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>",
  583. ];
  584. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  585. if(!empty($groupByDate)){
  586. $groupByDate->subhistory()->create($subHistory);
  587. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  588. }else{
  589. $history = History::create($historyData);
  590. $history->subhistory()->create($subHistory);
  591. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  592. }
  593. if($request->status == "Berbayar"){
  594. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  595. }else{
  596. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  597. }
  598. }else{
  599. $response = [
  600. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  601. ];
  602. return response()->json($response, 200);
  603. }
  604. }else{
  605. if($request->remark != ''){
  606. $compound->catatan_dari_admin = $request->remark;
  607. $compound->update_by = $request->current_id;
  608. $compound->save();
  609. $saved = $compound->save();
  610. if($saved){
  611. $gDate = $compound->created_at->format('F Y');
  612. $historyData = [
  613. 'tarikh_kumpulan' => $gDate,
  614. ];
  615. $subHistory = [
  616. 'no_siri' => $compound->ConfidentialFile->no_siri,
  617. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  618. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  619. ];
  620. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  621. if(!empty($groupByDate)){
  622. $groupByDate->subhistory()->create($subHistory);
  623. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  624. }else{
  625. $history = History::create($historyData);
  626. $history->subhistory()->create($subHistory);
  627. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  628. }
  629. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  630. }else{
  631. $response = [
  632. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  633. ];
  634. return response()->json($response, 200);
  635. }
  636. }else{
  637. $response = [
  638. 'success' => false, 'message' => 'Tiada kemaskini!',
  639. ];
  640. return response()->json($response, 200);
  641. }
  642. }
  643. }
  644. }else{
  645. $response = [
  646. 'success' => false,
  647. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  648. ];
  649. return response()->json($response, 200);
  650. }
  651. }
  652. /**
  653. * Remove the specified resource from storage.
  654. *
  655. * @param int $id
  656. * @return \Illuminate\Http\Response
  657. */
  658. public function destroy($id)
  659. {
  660. //
  661. }
  662. }