Dashboard sipadu mbip
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CompoundResourceController.php 43KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  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. "catatan" => $request->catatan,
  348. "lokasi_kejadian" => '-',
  349. 'latlong' => $request->Latlong,
  350. 'jbkod' => $request->jabatan,
  351. 'akta' => $faulty->deed_law_id,
  352. 'seksyen_kesalahan' => $faulty->_id,
  353. 'jumlah_asal_kompaun' => $faulty->amount,
  354. 'jumlah_kemaskini_kompaun' => '',
  355. 'dikeluarkan' => $staff->_id,
  356. "status" => 'Belum Bayar',
  357. "amount_payment" => '',
  358. "receipt" => '',
  359. "modul" => '03',
  360. "penguatkuasa" => '',
  361. "no_telefon" => $request->tel,
  362. "no_akaun_lesen" => $request->lesen,
  363. "maklumat_tambahan" => '-',
  364. ];
  365. }elseif($request->jenis == 'Pelbagai_JPB'){
  366. $compoundData = [
  367. 'jenis' => $request->jenis,
  368. 'kpd' => $kpd,
  369. 'nama' => $request->namaP,
  370. 'identity' => $request->noIc,
  371. 'nama_syarikat' => $request->namaS,
  372. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  373. 'alamat' => $request->alamat,
  374. "no_plate" => $request->no_plate,
  375. "no_cukai_jalan" => $request->no_cukai_jalan,
  376. "catatan" => $request->catatan,
  377. "lokasi_kejadian" => '-',
  378. 'latlong' => $request->Latlong,
  379. 'jbkod' => $request->jabatan,
  380. 'akta' => $faulty->deed_law_id,
  381. 'seksyen_kesalahan' => $faulty->_id,
  382. 'jumlah_asal_kompaun' => $faulty->amount,
  383. 'jumlah_kemaskini_kompaun' => '',
  384. 'dikeluarkan' => $staff->_id,
  385. "status" => 'Belum Bayar',
  386. "amount_payment" => '',
  387. "receipt" => '',
  388. "modul" => '03',
  389. "penguatkuasa" => '',
  390. "no_telefon" => $request->tel,
  391. "no_akaun_lesen" => $request->lesen,
  392. "maklumat_tambahan" => '-',
  393. ];
  394. }elseif($request->jenis == 'Pelbagai_PA'){
  395. $compoundData = [
  396. 'jenis' => $request->jenis,
  397. 'kpd' => $kpd,
  398. 'nama' => $request->namaP,
  399. 'identity' => $request->noIc,
  400. 'nama_syarikat' => $request->namaS,
  401. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  402. 'alamat' => $request->alamat,
  403. "no_plate" => $request->no_plate,
  404. "no_cukai_jalan" => $request->no_cukai_jalan,
  405. "catatan" => $request->catatan,
  406. "lokasi_kejadian" => '-',
  407. 'latlong' => $request->Latlong,
  408. 'jbkod' => $request->jabatan,
  409. 'akta' => $faulty->deed_law_id,
  410. 'seksyen_kesalahan' => $faulty->_id,
  411. 'jumlah_asal_kompaun' => $faulty->amount,
  412. 'jumlah_kemaskini_kompaun' => '',
  413. 'dikeluarkan' => $staff->_id,
  414. "status" => 'Belum Bayar',
  415. "amount_payment" => '',
  416. "receipt" => '',
  417. "modul" => '03',
  418. "penguatkuasa" => '',
  419. "no_telefon" => $request->tel,
  420. "no_akaun_lesen" => $request->lesen,
  421. "maklumat_tambahan" => '-',
  422. ];
  423. }
  424. elseif($request->jenis == 'Pelbagai_LESEN'){
  425. $compoundData = [
  426. 'jenis' => $request->jenis,
  427. 'kpd' => $kpd,
  428. 'nama' => $request->namaP,
  429. 'identity' => $request->noIc,
  430. 'nama_syarikat' => $request->namaS,
  431. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  432. 'alamat' => $request->alamat,
  433. "no_plate" => $request->no_plate,
  434. "no_cukai_jalan" => $request->no_cukai_jalan,
  435. "catatan" => $request->catatan,
  436. "lokasi_kejadian" => '-',
  437. 'latlong' => $request->Latlong,
  438. 'jbkod' => $request->jabatan,
  439. 'akta' => $faulty->deed_law_id,
  440. 'seksyen_kesalahan' => $faulty->_id,
  441. 'jumlah_asal_kompaun' => $faulty->amount,
  442. 'jumlah_kemaskini_kompaun' => '',
  443. 'dikeluarkan' => $staff->_id,
  444. "status" => 'Belum Bayar',
  445. "amount_payment" => '',
  446. "receipt" => '',
  447. "modul" => '03',
  448. "penguatkuasa" => '',
  449. "no_telefon" => $request->tel,
  450. "no_akaun_lesen" => $request->lesen,
  451. "maklumat_tambahan" => '-',
  452. ];
  453. }
  454. $file = ConfidentialFile::create($fileData);
  455. $saved = $file->compound()->create($compoundData);
  456. if($saved){
  457. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  458. // if(!empty($compound)){
  459. dispatch(new UpdateCompoundPrice($kpd));
  460. // $tawaran = '';
  461. // if($compound->jumlah_kemaskini_kompaun != ''){
  462. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  463. // }else{
  464. // $tawaran = $compound->jumlah_asal_kompaun;
  465. // }
  466. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  467. array_push($data, array('kpd' => $kpd));
  468. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  469. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  470. // }
  471. }
  472. }
  473. }
  474. }
  475. public function storeNotice(Request $request)
  476. {
  477. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  478. if(empty($staff)){
  479. return $this->sendError('Invalid', 'Staff not existed');
  480. }else {
  481. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  482. if(!empty($faulty)){
  483. $data = array();
  484. $countKPD = $this->compound->withTrashed()->count();
  485. do {
  486. $countKPD = $countKPD + 1;
  487. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  488. $kpd = 'KP' . $countKPD;
  489. $no_siri = date('yn').'-'.$countKPD;
  490. $fileData = [
  491. 'no_siri' => $no_siri,
  492. ];
  493. if($request->jenis == 'Parkir'){
  494. $compoundData = [
  495. 'jenis' => 'Parkir',
  496. 'kpd' => $kpd,
  497. 'nama' => '-',
  498. 'identity' => '-',
  499. 'alamat' => '-',
  500. "no_plate" => strtolower($request->no_plate),
  501. "no_cukai_jalan" => $request->noCukaijalan,
  502. "jenis_kenderaan" => $request->jenisKenderaan,
  503. "model_kenderaan" => $request->modelKenderaan,
  504. "warna_kenderaan" => $request->warnakenderaan,
  505. "nama_kawasan" => $request->namaKawasan,
  506. "nama_taman" => $request->namaTaman,
  507. "nama_jalan" => $request->namaJalan,
  508. "no_parking" => $request->noParking,
  509. "catatan" => $request->catatan,
  510. "lokasi_kejadian" => '-',
  511. 'latlong' => $request->Latlong,
  512. 'jbkod' => $request->jabatan,
  513. 'akta' => $faulty->deed_law_id,
  514. 'seksyen_kesalahan' => $faulty->_id,
  515. 'jumlah_asal_kompaun' => $faulty->amount,
  516. 'jumlah_kemaskini_kompaun' => '',
  517. 'dikeluarkan' => $staff->_id,
  518. "status" => 'Belum Bayar',
  519. "amount_payment" => '',
  520. "receipt" => '',
  521. "modul" => $request->modul,
  522. "penguatkuasa" => '',
  523. ];
  524. }elseif($request->jenis == 'Pelbagai_KT'){
  525. $compoundData = [
  526. 'jenis' => $request->jenis,
  527. 'kpd' => $kpd,
  528. 'nama' => $request->namaP,
  529. 'identity' => $request->noIc,
  530. 'nama_syarikat' => $request->namaS,
  531. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  532. 'alamat' => $request->alamat,
  533. "no_plate" => $request->no_plate,
  534. "no_cukai_jalan" => $request->no_cukai_jalan,
  535. "catatan" => $request->catatan,
  536. "lokasi_kejadian" => '-',
  537. 'latlong' => $request->Latlong,
  538. 'jbkod' => $request->jabatan,
  539. 'akta' => $faulty->deed_law_id,
  540. 'seksyen_kesalahan' => $faulty->_id,
  541. 'jumlah_asal_kompaun' => $faulty->amount,
  542. 'jumlah_kemaskini_kompaun' => '',
  543. 'dikeluarkan' => $staff->_id,
  544. "status" => 'Belum Bayar',
  545. "amount_payment" => '',
  546. "receipt" => '',
  547. "modul" => $request->modul,
  548. "penguatkuasa" => '',
  549. "no_telefon" => $request->tel,
  550. "no_akaun_lesen" => $request->lesen,
  551. "maklumat_tambahan" => '-',
  552. "tindakan" => $request->tindakan,
  553. "tempoh" => $request->tempoh,
  554. ];
  555. }elseif($request->jenis == 'Pelbagai_JPB'){
  556. $compoundData = [
  557. 'jenis' => $request->jenis,
  558. 'kpd' => $kpd,
  559. 'nama' => $request->namaP,
  560. 'identity' => $request->noIc,
  561. 'nama_syarikat' => $request->namaS,
  562. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  563. 'alamat' => $request->alamat,
  564. "no_plate" => $request->no_plate,
  565. "no_cukai_jalan" => $request->no_cukai_jalan,
  566. "catatan" => $request->catatan,
  567. "lokasi_kejadian" => '-',
  568. 'latlong' => $request->Latlong,
  569. 'jbkod' => $request->jabatan,
  570. 'akta' => $faulty->deed_law_id,
  571. 'seksyen_kesalahan' => $faulty->_id,
  572. 'jumlah_asal_kompaun' => $faulty->amount,
  573. 'jumlah_kemaskini_kompaun' => '',
  574. 'dikeluarkan' => $staff->_id,
  575. "status" => 'Belum Bayar',
  576. "amount_payment" => '',
  577. "receipt" => '',
  578. "modul" => $request->modul,
  579. "penguatkuasa" => '',
  580. "no_telefon" => $request->tel,
  581. "no_akaun_lesen" => $request->lesen,
  582. "maklumat_tambahan" => '-',
  583. "tindakan" => $request->tindakan,
  584. "tempoh" => $request->tempoh,
  585. ];
  586. }
  587. elseif($request->jenis == 'Pelbagai_LESEN'){
  588. $compoundData = [
  589. 'jenis' => $request->jenis,
  590. 'kpd' => $kpd,
  591. 'nama' => $request->namaP,
  592. 'identity' => $request->noIc,
  593. 'nama_syarikat' => $request->namaS,
  594. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  595. 'alamat' => $request->alamat,
  596. "no_plate" => $request->no_plate,
  597. "no_cukai_jalan" => $request->no_cukai_jalan,
  598. "catatan" => $request->catatan,
  599. "lokasi_kejadian" => '-',
  600. 'latlong' => $request->Latlong,
  601. 'jbkod' => $request->jabatan,
  602. 'akta' => $faulty->deed_law_id,
  603. 'seksyen_kesalahan' => $faulty->_id,
  604. 'jumlah_asal_kompaun' => $faulty->amount,
  605. 'jumlah_kemaskini_kompaun' => '',
  606. 'dikeluarkan' => $staff->_id,
  607. "status" => 'Belum Bayar',
  608. "amount_payment" => '',
  609. "receipt" => '',
  610. "modul" => $request->modul,
  611. "penguatkuasa" => '',
  612. "no_telefon" => $request->tel,
  613. "no_akaun_lesen" => $request->lesen,
  614. "tempoh" => $request->tempoh,
  615. ];
  616. }
  617. elseif($request->jenis == 'Pelbagai_PA'){
  618. $compoundData = [
  619. 'jenis' => $request->jenis,
  620. 'kpd' => $kpd,
  621. 'nama' => $request->namaP,
  622. 'identity' => $request->noIc,
  623. 'nama_syarikat' => $request->namaS,
  624. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  625. 'alamat' => $request->alamat,
  626. "no_plate" => $request->no_plate,
  627. "no_cukai_jalan" => $request->no_cukai_jalan,
  628. "catatan" => $request->catatan,
  629. "lokasi_kejadian" => '-',
  630. 'latlong' => $request->Latlong,
  631. 'jbkod' => $request->jabatan,
  632. 'akta' => $faulty->deed_law_id,
  633. 'seksyen_kesalahan' => $faulty->_id,
  634. 'jumlah_asal_kompaun' => $faulty->amount,
  635. 'jumlah_kemaskini_kompaun' => '',
  636. 'dikeluarkan' => $staff->_id,
  637. "status" => 'Belum Bayar',
  638. "amount_payment" => '',
  639. "receipt" => '',
  640. "modul" => $request->modul,
  641. "penguatkuasa" => '',
  642. "no_telefon" => $request->tel,
  643. "no_akaun_lesen" => $request->lesen,
  644. "bil_haiwan" => $request->bil_haiwan,
  645. ];
  646. }
  647. $file = ConfidentialFile::create($fileData);
  648. $saved = $file->compound()->create($compoundData);
  649. if($saved){
  650. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  651. // if(!empty($compound)){
  652. dispatch(new UpdateCompoundPrice($kpd));
  653. // $tawaran = '';
  654. // if($compound->jumlah_kemaskini_kompaun != ''){
  655. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  656. // }else{
  657. // $tawaran = $compound->jumlah_asal_kompaun;
  658. // }
  659. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  660. array_push($data, array('kpd' => $kpd));
  661. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  662. // }
  663. }
  664. }
  665. }
  666. }
  667. /**
  668. * Display the specified resource.
  669. *
  670. * @param int $id
  671. * @return \Illuminate\Http\Response
  672. */
  673. public function show($id)
  674. {
  675. //
  676. }
  677. /**
  678. * Show the form for editing the specified resource.
  679. *
  680. * @param int $id
  681. * @return \Illuminate\Http\Response
  682. */
  683. public function edit($id)
  684. {
  685. //
  686. }
  687. /**
  688. * Update the specified resource in storage.
  689. *
  690. * @param \Illuminate\Http\Request $request
  691. * @param int $id
  692. * @return \Illuminate\Http\Response
  693. */
  694. public function update(Request $request, $id)
  695. {
  696. //
  697. }
  698. public function updateStatusPaymentViaDashboard(Request $request)
  699. {
  700. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  701. $staff = StaffDetail::find($request->current_id);
  702. if(!empty($compound) && !empty($staff)){
  703. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  704. if($compound->status != $request->status){
  705. $compound->status = $request->status;
  706. $compound->catatan_dari_admin = $request->remark;
  707. $compound->amount_payment = $request->amount;
  708. $compound->update_by = $request->current_id;
  709. $saved = $compound->save();
  710. if($saved){
  711. $gDate = $compound->created_at->format('F Y');
  712. $historyData = [
  713. 'tarikh_kumpulan' => $gDate,
  714. ];
  715. $subHistory = [
  716. 'no_siri' => $compound->ConfidentialFile->no_siri,
  717. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  718. '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>",
  719. ];
  720. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  721. if(!empty($groupByDate)){
  722. $groupByDate->subhistory()->create($subHistory);
  723. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  724. }else{
  725. $history = History::create($historyData);
  726. $history->subhistory()->create($subHistory);
  727. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  728. }
  729. if($request->status == "Berbayar"){
  730. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  731. }else{
  732. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  733. }
  734. }else{
  735. $response = [
  736. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  737. ];
  738. return response()->json($response, 200);
  739. }
  740. }else{
  741. if($request->remark != ''){
  742. $compound->catatan_dari_admin = $request->remark;
  743. $compound->update_by = $request->current_id;
  744. $compound->save();
  745. $saved = $compound->save();
  746. if($saved){
  747. $gDate = $compound->created_at->format('F Y');
  748. $historyData = [
  749. 'tarikh_kumpulan' => $gDate,
  750. ];
  751. $subHistory = [
  752. 'no_siri' => $compound->ConfidentialFile->no_siri,
  753. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  754. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  755. ];
  756. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  757. if(!empty($groupByDate)){
  758. $groupByDate->subhistory()->create($subHistory);
  759. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  760. }else{
  761. $history = History::create($historyData);
  762. $history->subhistory()->create($subHistory);
  763. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  764. }
  765. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  766. }else{
  767. $response = [
  768. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  769. ];
  770. return response()->json($response, 200);
  771. }
  772. }else{
  773. $response = [
  774. 'success' => false, 'message' => 'Tiada kemaskini!',
  775. ];
  776. return response()->json($response, 200);
  777. }
  778. }
  779. }else{
  780. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  781. $compound->status = $request->status;
  782. $compound->catatan_dari_admin = $request->remark;
  783. $compound->amount_payment = $request->amount;
  784. $compound->update_by = $request->current_id;
  785. $saved = $compound->save();
  786. if($saved){
  787. $gDate = $compound->created_at->format('F Y');
  788. $historyData = [
  789. 'tarikh_kumpulan' => $gDate,
  790. ];
  791. $subHistory = [
  792. 'no_siri' => $compound->ConfidentialFile->no_siri,
  793. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  794. '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>",
  795. ];
  796. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  797. if(!empty($groupByDate)){
  798. $groupByDate->subhistory()->create($subHistory);
  799. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  800. }else{
  801. $history = History::create($historyData);
  802. $history->subhistory()->create($subHistory);
  803. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  804. }
  805. if($request->status == "Berbayar"){
  806. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  807. }else{
  808. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  809. }
  810. }else{
  811. $response = [
  812. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  813. ];
  814. return response()->json($response, 200);
  815. }
  816. }else{
  817. if($request->remark != ''){
  818. $compound->catatan_dari_admin = $request->remark;
  819. $compound->update_by = $request->current_id;
  820. $compound->save();
  821. $saved = $compound->save();
  822. if($saved){
  823. $gDate = $compound->created_at->format('F Y');
  824. $historyData = [
  825. 'tarikh_kumpulan' => $gDate,
  826. ];
  827. $subHistory = [
  828. 'no_siri' => $compound->ConfidentialFile->no_siri,
  829. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  830. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  831. ];
  832. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  833. if(!empty($groupByDate)){
  834. $groupByDate->subhistory()->create($subHistory);
  835. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  836. }else{
  837. $history = History::create($historyData);
  838. $history->subhistory()->create($subHistory);
  839. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  840. }
  841. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  842. }else{
  843. $response = [
  844. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  845. ];
  846. return response()->json($response, 200);
  847. }
  848. }else{
  849. $response = [
  850. 'success' => false, 'message' => 'Tiada kemaskini!',
  851. ];
  852. return response()->json($response, 200);
  853. }
  854. }
  855. }
  856. }else{
  857. $response = [
  858. 'success' => false,
  859. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  860. ];
  861. return response()->json($response, 200);
  862. }
  863. }
  864. /**
  865. * Remove the specified resource from storage.
  866. *
  867. * @param int $id
  868. * @return \Illuminate\Http\Response
  869. */
  870. public function destroy($id)
  871. {
  872. //
  873. }
  874. }