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

CompoundResourceController.php 44KB

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