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 38KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start, $end));
  50. if($modul == 'All'){
  51. $compound = $compound;
  52. }else if($modul == '06-07'){
  53. $compound = $compound->where(function($q){
  54. $q->where(function($query){
  55. $query->where('modul', '06')->orWhere('modul','07');
  56. });
  57. });
  58. }else {
  59. $compound = $compound->where('modul', $modul);
  60. }
  61. if($status == 'All'){
  62. $compound = $compound;
  63. }else {
  64. $compound = $compound->where('status', $status);
  65. }
  66. return $compound;
  67. }
  68. private function searchCompoundAllWithoutDate($jenis,$modul,$status){
  69. $compound = Compound::where('jenis', $jenis);
  70. if($modul == 'All'){
  71. $compound = $compound;
  72. }else 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. });
  78. }else {
  79. $compound = $compound->where('modul', $modul);
  80. }
  81. if($status == 'All'){
  82. $compound = $compound;
  83. }else {
  84. $compound = $compound->where('status', $status);
  85. }
  86. return $compound;
  87. }
  88. private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date){
  89. if(!empty($start_date)){
  90. $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date);
  91. }else{
  92. $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status);
  93. }
  94. if($enforcer == 'All'){
  95. return $compound;
  96. }else {
  97. $compound = $compound->where('dikeluarkan', $enforcer);
  98. return $compound;
  99. }
  100. }
  101. private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department){
  102. $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date);
  103. if($faulty == 'All'){
  104. return $compound->whereIn('jbkod',$department);
  105. }else {
  106. $compound = $compound->where('seksyen_kesalahan', $faulty);
  107. return $compound;
  108. }
  109. }
  110. private function searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no){
  111. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department);
  112. if(!empty($plate_no)){
  113. $compound = $compound->where('no_plate',$plate_no);
  114. return $compound;
  115. }else{
  116. return $compound;
  117. }
  118. }
  119. private function searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd){
  120. $compound = $this->searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no);
  121. if(!empty($kpd)){
  122. $compound = $compound->where('kpd',$kpd);
  123. return $compound;
  124. }else{
  125. $compound = $compound->whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal']);
  126. return $compound;
  127. }
  128. }
  129. private function searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no){
  130. $compound = $this->searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd);
  131. if(!empty($company_no)){
  132. $compound = $compound->where('no_daftar_syarikat','LIKE',$company_no);
  133. return $compound;
  134. }else{
  135. return $compound;
  136. }
  137. }
  138. private function searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric){
  139. $compound = $this->searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no);
  140. if(!empty($nric)){
  141. $compound = $compound->where('identity',$nric);
  142. return $compound;
  143. }else{
  144. return $compound;
  145. }
  146. }
  147. private function searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license){
  148. $compound = $this->searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric);
  149. if(!empty($license)){
  150. $compound = $compound->where('no_akaun_lesen', 'exists', true)->where('no_akaun_lesen',$license);
  151. return $compound;
  152. }else{
  153. return $compound;
  154. }
  155. }
  156. private function searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP){
  157. $compound = $this->searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license);
  158. if(!empty($namaP)){
  159. $compound = $compound->where('nama', 'LIKE', "%{$namaP}%");
  160. return $compound;
  161. }else{
  162. return $compound;
  163. }
  164. }
  165. private function searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name){
  166. $compound = $this->searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP);
  167. if(!empty($company_name)){
  168. $compound = $compound->where('nama_syarikat', 'exists', true)->where('nama_syarikat', 'LIKE', '%{$company_name%}');
  169. return $compound;
  170. }else{
  171. return $compound;
  172. }
  173. }
  174. public function index(Request $request)
  175. {
  176. $per_page = '';
  177. $kpd = '';
  178. $modul = 'All';
  179. $status = 'All';
  180. $jenis = 'Pelbagai_JPB';
  181. if(!empty($request->department)){
  182. $department = ["5df721c5cde7fd741433c6b2","5d957899f3da686c08192026","5d9d4a699b802d5a31031a8a","5d9d4db1aa95fa07f7245e28","5d9d5955eb4f92300927f188","5d9e965fec0023467756a02a","5d9eba38e4be2267877896a8"];
  183. }else {
  184. $department = [];
  185. }
  186. $start_date = '2020-07-18';
  187. $end_date = '2020-08-14';
  188. $enforcer = 'All';
  189. $faulty = 'All';
  190. $plate_no = strtolower('');
  191. $company_no = strtolower('');
  192. $nric = '';
  193. $license = '';
  194. $namaP = '';
  195. $company_name = '';
  196. /////////////////////////////////////////////////////////////////////////////////
  197. // $per_page = $request->per_page;
  198. // $kpd = $request->kpd;
  199. // $modul = $request->modul;
  200. // $status = $request->status;
  201. // $jenis = $request->type;
  202. // if(!empty($request->department)){
  203. // $department = json_decode($request->department);
  204. // }else {
  205. // $department = [];
  206. // }
  207. // $start_date = $request->start_date;
  208. // $end_date = $request->end_date;
  209. // $enforcer = $request->enforcer;
  210. // $faulty = $request->faulty;
  211. // $plate_no = strtolower($request->plate_no);
  212. // $company_no = strtolower($request->company_no);
  213. // $nric = $request->nric;
  214. // $license = $request->license;
  215. // $namaP = $request->nameP;
  216. // $company_name = $request->company_name;
  217. $nested_data = array();
  218. $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();
  219. return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
  220. ->addColumn('index', function($row) {
  221. $curr = Carbon::now();
  222. $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
  223. if($curr->diffInDays($dtC) <= 3){
  224. $html = 'New';
  225. }else{ $html = ''; }
  226. return $html;
  227. })->addColumn('status_kemaskini', function($row) {
  228. $data = '';
  229. if($row['status'] == 'Berbayar'){
  230. $data = '<b>'.$row['status'].'</b><div style="margin-top: 8px"><span>Bayaran: </span><br/>';
  231. $data .= 'RM '.$row['amount_payment'].'</div>';
  232. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  233. if($row['updated_by'] !== null ){
  234. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  235. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  236. }else {
  237. if(!empty($row['tarikh_bayar']) && $row['tarikh_bayar'] != ''){
  238. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  239. $data .= $row['tarikh_bayar'].' <br/>'.$row['updates_by'].'</div>';
  240. }else {
  241. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  242. $data .= $row['updated_at'].' <br/>'.$row['updates_by'].'</div>';
  243. }
  244. }
  245. }else if($row['status'] == 'Belum Bayar' && $row['updated_by'] !== null){
  246. $data = '<b>'.$row['status'].'</b>';
  247. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  248. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  249. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  250. }else if($row['status'] == 'Batal' && $row['updated_by'] !== null){
  251. $data = '<b>'.$row['status'].'</b>';
  252. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  253. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  254. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  255. }else if($row['status'] == 'Buang' && $row['updated_by'] !== null){
  256. $data = '<b>'.$row['status'].'</b>';
  257. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  258. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  259. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  260. }
  261. else
  262. {
  263. $data = $row['status'];
  264. }
  265. return $data;
  266. })->addColumn('kesalahan', function($row) {
  267. $data = '<b>Seksyen '.$row['faulty_skter'].'</b><br/>'.$row['faulty_name'];
  268. return $data;
  269. })->rawColumns(['index','status_kemaskini','kesalahan'])->make(true);
  270. }
  271. /**
  272. * Show the form for creating a new resource.
  273. *
  274. * @return \Illuminate\Http\Response
  275. */
  276. public function create()
  277. {
  278. //
  279. }
  280. /**
  281. * Store a newly created resource in storage.
  282. *
  283. * @param \Illuminate\Http\Request $request
  284. * @return \Illuminate\Http\Response
  285. */
  286. public function store(Request $request)
  287. {
  288. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  289. if(empty($staff)){
  290. return $this->sendError('Invalid', 'Staff not existed');
  291. }else {
  292. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  293. if(!empty($faulty)){
  294. $data = array();
  295. $countKPD = $this->compound->withTrashed()->count();
  296. do {
  297. $countKPD = $countKPD + 1;
  298. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  299. $kpd = 'KP' . $countKPD;
  300. $no_siri = date('yn').'-'.$countKPD;
  301. $fileData = [
  302. 'no_siri' => $no_siri,
  303. ];
  304. if($request->jenis == 'Parkir'){
  305. $compoundData = [
  306. 'jenis' => 'Parkir',
  307. 'kpd' => $kpd,
  308. 'nama' => '-',
  309. 'identity' => '-',
  310. 'alamat' => '-',
  311. "no_plate" => strtolower($request->no_plate),
  312. "no_cukai_jalan" => $request->noCukaijalan,
  313. "jenis_kenderaan" => $request->jenisKenderaan,
  314. "model_kenderaan" => $request->modelKenderaan,
  315. "warna_kenderaan" => $request->warnakenderaan,
  316. "nama_kawasan" => $request->namaKawasan,
  317. "nama_taman" => $request->namaTaman,
  318. "nama_jalan" => $request->namaJalan,
  319. "no_parking" => $request->noParking,
  320. "catatan" => $request->catatan,
  321. "lokasi_kejadian" => '-',
  322. 'latlong' => $request->Latlong,
  323. 'jbkod' => $request->jabatan,
  324. 'akta' => $faulty->deed_law_id,
  325. 'seksyen_kesalahan' => $faulty->_id,
  326. 'jumlah_asal_kompaun' => $faulty->amount,
  327. 'jumlah_kemaskini_kompaun' => '',
  328. 'dikeluarkan' => $staff->_id,
  329. "status" => 'Belum Bayar',
  330. "amount_payment" => '',
  331. "receipt" => '',
  332. "modul" => '03',
  333. "penguatkuasa" => '',
  334. ];
  335. }elseif($request->jenis == 'Pelbagai_KT'){
  336. $compoundData = [
  337. 'jenis' => $request->jenis,
  338. 'kpd' => $kpd,
  339. 'nama' => $request->namaP,
  340. 'identity' => $request->noIc,
  341. 'nama_syarikat' => $request->namaS,
  342. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  343. 'alamat' => $request->alamat,
  344. "no_plate" => $request->no_plate,
  345. "no_cukai_jalan" => $request->no_cukai_jalan,
  346. "catatan" => $request->catatan,
  347. "lokasi_kejadian" => '-',
  348. 'latlong' => $request->Latlong,
  349. 'jbkod' => $request->jabatan,
  350. 'akta' => $faulty->deed_law_id,
  351. 'seksyen_kesalahan' => $faulty->_id,
  352. 'jumlah_asal_kompaun' => $faulty->amount,
  353. 'jumlah_kemaskini_kompaun' => '',
  354. 'dikeluarkan' => $staff->_id,
  355. "status" => 'Belum Bayar',
  356. "amount_payment" => '',
  357. "receipt" => '',
  358. "modul" => '03',
  359. "penguatkuasa" => '',
  360. "no_telefon" => $request->tel,
  361. "no_akaun_lesen" => $request->lesen,
  362. "maklumat_tambahan" => '-',
  363. ];
  364. }elseif($request->jenis == 'Pelbagai_JPB'){
  365. $compoundData = [
  366. 'jenis' => $request->jenis,
  367. 'kpd' => $kpd,
  368. 'nama' => $request->namaP,
  369. 'identity' => $request->noIc,
  370. 'nama_syarikat' => $request->namaS,
  371. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  372. 'alamat' => $request->alamat,
  373. "no_plate" => $request->no_plate,
  374. "no_cukai_jalan" => $request->no_cukai_jalan,
  375. "catatan" => $request->catatan,
  376. "lokasi_kejadian" => '-',
  377. 'latlong' => $request->Latlong,
  378. 'jbkod' => $request->jabatan,
  379. 'akta' => $faulty->deed_law_id,
  380. 'seksyen_kesalahan' => $faulty->_id,
  381. 'jumlah_asal_kompaun' => $faulty->amount,
  382. 'jumlah_kemaskini_kompaun' => '',
  383. 'dikeluarkan' => $staff->_id,
  384. "status" => 'Belum Bayar',
  385. "amount_payment" => '',
  386. "receipt" => '',
  387. "modul" => '03',
  388. "penguatkuasa" => '',
  389. "no_telefon" => $request->tel,
  390. "no_akaun_lesen" => $request->lesen,
  391. "maklumat_tambahan" => '-',
  392. ];
  393. }
  394. $file = ConfidentialFile::create($fileData);
  395. $saved = $file->compound()->create($compoundData);
  396. if($saved){
  397. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  398. // if(!empty($compound)){
  399. dispatch(new UpdateCompoundPrice($kpd));
  400. // $tawaran = '';
  401. // if($compound->jumlah_kemaskini_kompaun != ''){
  402. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  403. // }else{
  404. // $tawaran = $compound->jumlah_asal_kompaun;
  405. // }
  406. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  407. array_push($data, array('kpd' => $kpd));
  408. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  409. // }
  410. }
  411. }
  412. }
  413. }
  414. public function storeNotice(Request $request)
  415. {
  416. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  417. if(empty($staff)){
  418. return $this->sendError('Invalid', 'Staff not existed');
  419. }else {
  420. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  421. if(!empty($faulty)){
  422. $data = array();
  423. $countKPD = $this->compound->withTrashed()->count();
  424. do {
  425. $countKPD = $countKPD + 1;
  426. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  427. $kpd = 'KP' . $countKPD;
  428. $no_siri = date('yn').'-'.$countKPD;
  429. $fileData = [
  430. 'no_siri' => $no_siri,
  431. ];
  432. if($request->jenis == 'Parkir'){
  433. $compoundData = [
  434. 'jenis' => 'Parkir',
  435. 'kpd' => $kpd,
  436. 'nama' => '-',
  437. 'identity' => '-',
  438. 'alamat' => '-',
  439. "no_plate" => strtolower($request->no_plate),
  440. "no_cukai_jalan" => $request->noCukaijalan,
  441. "jenis_kenderaan" => $request->jenisKenderaan,
  442. "model_kenderaan" => $request->modelKenderaan,
  443. "warna_kenderaan" => $request->warnakenderaan,
  444. "nama_kawasan" => $request->namaKawasan,
  445. "nama_taman" => $request->namaTaman,
  446. "nama_jalan" => $request->namaJalan,
  447. "no_parking" => $request->noParking,
  448. "catatan" => $request->catatan,
  449. "lokasi_kejadian" => '-',
  450. 'latlong' => $request->Latlong,
  451. 'jbkod' => $request->jabatan,
  452. 'akta' => $faulty->deed_law_id,
  453. 'seksyen_kesalahan' => $faulty->_id,
  454. 'jumlah_asal_kompaun' => $faulty->amount,
  455. 'jumlah_kemaskini_kompaun' => '',
  456. 'dikeluarkan' => $staff->_id,
  457. "status" => 'Belum Bayar',
  458. "amount_payment" => '',
  459. "receipt" => '',
  460. "modul" => '05',
  461. "penguatkuasa" => '',
  462. ];
  463. }elseif($request->jenis == 'Pelbagai_KT'){
  464. $compoundData = [
  465. 'jenis' => $request->jenis,
  466. 'kpd' => $kpd,
  467. 'nama' => $request->namaP,
  468. 'identity' => $request->noIc,
  469. 'nama_syarikat' => $request->namaS,
  470. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  471. 'alamat' => $request->alamat,
  472. "no_plate" => $request->no_plate,
  473. "no_cukai_jalan" => $request->no_cukai_jalan,
  474. "catatan" => $request->catatan,
  475. "lokasi_kejadian" => '-',
  476. 'latlong' => $request->Latlong,
  477. 'jbkod' => $request->jabatan,
  478. 'akta' => $faulty->deed_law_id,
  479. 'seksyen_kesalahan' => $faulty->_id,
  480. 'jumlah_asal_kompaun' => $faulty->amount,
  481. 'jumlah_kemaskini_kompaun' => '',
  482. 'dikeluarkan' => $staff->_id,
  483. "status" => 'Belum Bayar',
  484. "amount_payment" => '',
  485. "receipt" => '',
  486. "modul" => '05',
  487. "penguatkuasa" => '',
  488. "no_telefon" => $request->tel,
  489. "no_akaun_lesen" => $request->lesen,
  490. "maklumat_tambahan" => '-',
  491. ];
  492. }elseif($request->jenis == 'Pelbagai_JPB'){
  493. $compoundData = [
  494. 'jenis' => $request->jenis,
  495. 'kpd' => $kpd,
  496. 'nama' => $request->namaP,
  497. 'identity' => $request->noIc,
  498. 'nama_syarikat' => $request->namaS,
  499. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  500. 'alamat' => $request->alamat,
  501. "no_plate" => $request->no_plate,
  502. "no_cukai_jalan" => $request->no_cukai_jalan,
  503. "catatan" => $request->catatan,
  504. "lokasi_kejadian" => '-',
  505. 'latlong' => $request->Latlong,
  506. 'jbkod' => $request->jabatan,
  507. 'akta' => $faulty->deed_law_id,
  508. 'seksyen_kesalahan' => $faulty->_id,
  509. 'jumlah_asal_kompaun' => $faulty->amount,
  510. 'jumlah_kemaskini_kompaun' => '',
  511. 'dikeluarkan' => $staff->_id,
  512. "status" => 'Belum Bayar',
  513. "amount_payment" => '',
  514. "receipt" => '',
  515. "modul" => '05',
  516. "penguatkuasa" => '',
  517. "no_telefon" => $request->tel,
  518. "no_akaun_lesen" => $request->lesen,
  519. "maklumat_tambahan" => '-',
  520. ];
  521. }
  522. elseif($request->jenis == 'Lesen'){
  523. $compoundData = [
  524. 'jenis' => $request->jenis,
  525. 'kpd' => $kpd,
  526. 'nama' => $request->namaP,
  527. 'identity' => $request->noIc,
  528. 'nama_syarikat' => $request->namaS,
  529. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  530. 'alamat' => $request->alamat,
  531. "no_plate" => $request->no_plate,
  532. "no_cukai_jalan" => $request->no_cukai_jalan,
  533. "catatan" => $request->catatan,
  534. "lokasi_kejadian" => '-',
  535. 'latlong' => $request->Latlong,
  536. 'jbkod' => $request->jabatan,
  537. 'akta' => $faulty->deed_law_id,
  538. 'seksyen_kesalahan' => $faulty->_id,
  539. 'jumlah_asal_kompaun' => $faulty->amount,
  540. 'jumlah_kemaskini_kompaun' => '',
  541. 'dikeluarkan' => $staff->_id,
  542. "status" => 'Belum Bayar',
  543. "amount_payment" => '',
  544. "receipt" => '',
  545. "modul" => '05',
  546. "penguatkuasa" => '',
  547. "no_telefon" => $request->tel,
  548. "no_akaun_lesen" => $request->lesen,
  549. "bil_haiwan" => $request->bil_haiwan,
  550. ];
  551. }
  552. $file = ConfidentialFile::create($fileData);
  553. $saved = $file->compound()->create($compoundData);
  554. if($saved){
  555. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  556. // if(!empty($compound)){
  557. dispatch(new UpdateCompoundPrice($kpd));
  558. // $tawaran = '';
  559. // if($compound->jumlah_kemaskini_kompaun != ''){
  560. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  561. // }else{
  562. // $tawaran = $compound->jumlah_asal_kompaun;
  563. // }
  564. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  565. array_push($data, array('kpd' => $kpd));
  566. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  567. // }
  568. }
  569. }
  570. }
  571. }
  572. /**
  573. * Display the specified resource.
  574. *
  575. * @param int $id
  576. * @return \Illuminate\Http\Response
  577. */
  578. public function show($id)
  579. {
  580. //
  581. }
  582. /**
  583. * Show the form for editing the specified resource.
  584. *
  585. * @param int $id
  586. * @return \Illuminate\Http\Response
  587. */
  588. public function edit($id)
  589. {
  590. //
  591. }
  592. /**
  593. * Update the specified resource in storage.
  594. *
  595. * @param \Illuminate\Http\Request $request
  596. * @param int $id
  597. * @return \Illuminate\Http\Response
  598. */
  599. public function update(Request $request, $id)
  600. {
  601. //
  602. }
  603. public function updateStatusPaymentViaDashboard(Request $request)
  604. {
  605. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  606. $staff = StaffDetail::find($request->current_id);
  607. if(!empty($compound) && !empty($staff)){
  608. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  609. if($compound->status != $request->status){
  610. $compound->status = $request->status;
  611. $compound->catatan_dari_admin = $request->remark;
  612. $compound->amount_payment = $request->amount;
  613. $compound->update_by = $request->current_id;
  614. $saved = $compound->save();
  615. if($saved){
  616. $gDate = $compound->created_at->format('F Y');
  617. $historyData = [
  618. 'tarikh_kumpulan' => $gDate,
  619. ];
  620. $subHistory = [
  621. 'no_siri' => $compound->ConfidentialFile->no_siri,
  622. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  623. '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>",
  624. ];
  625. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  626. if(!empty($groupByDate)){
  627. $groupByDate->subhistory()->create($subHistory);
  628. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  629. }else{
  630. $history = History::create($historyData);
  631. $history->subhistory()->create($subHistory);
  632. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  633. }
  634. if($request->status == "Berbayar"){
  635. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  636. }else{
  637. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  638. }
  639. }else{
  640. $response = [
  641. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  642. ];
  643. return response()->json($response, 200);
  644. }
  645. }else{
  646. if($request->remark != ''){
  647. $compound->catatan_dari_admin = $request->remark;
  648. $compound->update_by = $request->current_id;
  649. $compound->save();
  650. $saved = $compound->save();
  651. if($saved){
  652. $gDate = $compound->created_at->format('F Y');
  653. $historyData = [
  654. 'tarikh_kumpulan' => $gDate,
  655. ];
  656. $subHistory = [
  657. 'no_siri' => $compound->ConfidentialFile->no_siri,
  658. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  659. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  660. ];
  661. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  662. if(!empty($groupByDate)){
  663. $groupByDate->subhistory()->create($subHistory);
  664. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  665. }else{
  666. $history = History::create($historyData);
  667. $history->subhistory()->create($subHistory);
  668. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  669. }
  670. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  671. }else{
  672. $response = [
  673. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  674. ];
  675. return response()->json($response, 200);
  676. }
  677. }else{
  678. $response = [
  679. 'success' => false, 'message' => 'Tiada kemaskini!',
  680. ];
  681. return response()->json($response, 200);
  682. }
  683. }
  684. }else{
  685. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  686. $compound->status = $request->status;
  687. $compound->catatan_dari_admin = $request->remark;
  688. $compound->amount_payment = $request->amount;
  689. $compound->update_by = $request->current_id;
  690. $saved = $compound->save();
  691. if($saved){
  692. $gDate = $compound->created_at->format('F Y');
  693. $historyData = [
  694. 'tarikh_kumpulan' => $gDate,
  695. ];
  696. $subHistory = [
  697. 'no_siri' => $compound->ConfidentialFile->no_siri,
  698. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  699. '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>",
  700. ];
  701. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  702. if(!empty($groupByDate)){
  703. $groupByDate->subhistory()->create($subHistory);
  704. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  705. }else{
  706. $history = History::create($historyData);
  707. $history->subhistory()->create($subHistory);
  708. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  709. }
  710. if($request->status == "Berbayar"){
  711. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  712. }else{
  713. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  714. }
  715. }else{
  716. $response = [
  717. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  718. ];
  719. return response()->json($response, 200);
  720. }
  721. }else{
  722. if($request->remark != ''){
  723. $compound->catatan_dari_admin = $request->remark;
  724. $compound->update_by = $request->current_id;
  725. $compound->save();
  726. $saved = $compound->save();
  727. if($saved){
  728. $gDate = $compound->created_at->format('F Y');
  729. $historyData = [
  730. 'tarikh_kumpulan' => $gDate,
  731. ];
  732. $subHistory = [
  733. 'no_siri' => $compound->ConfidentialFile->no_siri,
  734. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  735. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  736. ];
  737. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  738. if(!empty($groupByDate)){
  739. $groupByDate->subhistory()->create($subHistory);
  740. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  741. }else{
  742. $history = History::create($historyData);
  743. $history->subhistory()->create($subHistory);
  744. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  745. }
  746. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  747. }else{
  748. $response = [
  749. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  750. ];
  751. return response()->json($response, 200);
  752. }
  753. }else{
  754. $response = [
  755. 'success' => false, 'message' => 'Tiada kemaskini!',
  756. ];
  757. return response()->json($response, 200);
  758. }
  759. }
  760. }
  761. }else{
  762. $response = [
  763. 'success' => false,
  764. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  765. ];
  766. return response()->json($response, 200);
  767. }
  768. }
  769. /**
  770. * Remove the specified resource from storage.
  771. *
  772. * @param int $id
  773. * @return \Illuminate\Http\Response
  774. */
  775. public function destroy($id)
  776. {
  777. //
  778. }
  779. }