Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompoundResourceController.php 58KB

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