Dashboard sipadu mbip
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CompoundResourceController.php 44KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  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" => '03',
  534. "penguatkuasa" => '',
  535. ];
  536. }elseif($request->jenis == 'Pelbagai_KT'){
  537. $compoundData = [
  538. 'jenis' => 'Parkir',
  539. 'kpd' => $kpd,
  540. 'nama' => '-',
  541. 'identity' => '-',
  542. 'alamat' => '-',
  543. "no_plate" => strtolower($request->no_plate),
  544. "no_cukai_jalan" => $request->noCukaijalan,
  545. "jenis_kenderaan" => $request->jenisKenderaan,
  546. "model_kenderaan" => $request->modelKenderaan,
  547. "warna_kenderaan" => $request->warnakenderaan,
  548. "nama_kawasan" => $request->namaKawasan,
  549. "nama_taman" => $request->namaTaman,
  550. "nama_jalan" => $request->namaJalan,
  551. "no_parking" => $request->noParking,
  552. "catatan" => $request->catatan,
  553. "lokasi_kejadian" => '-',
  554. 'latlong' => $request->Latlong,
  555. 'jbkod' => $request->jabatan,
  556. 'akta' => $faulty->deed_law_id,
  557. 'seksyen_kesalahan' => $faulty->_id,
  558. 'jumlah_asal_kompaun' => $faulty->amount,
  559. 'jumlah_kemaskini_kompaun' => '',
  560. 'dikeluarkan' => $staff->_id,
  561. "status" => 'Belum Bayar',
  562. "amount_payment" => '',
  563. "receipt" => '',
  564. "modul" => '03',
  565. "penguatkuasa" => '',
  566. ];
  567. }elseif($request->jenis == 'Pelbagai_JPB'){
  568. $compoundData = [
  569. 'jenis' => 'Parkir',
  570. 'kpd' => $kpd,
  571. 'nama' => '-',
  572. 'identity' => '-',
  573. 'alamat' => '-',
  574. "no_plate" => strtolower($request->no_plate),
  575. "no_cukai_jalan" => $request->noCukaijalan,
  576. "jenis_kenderaan" => $request->jenisKenderaan,
  577. "model_kenderaan" => $request->modelKenderaan,
  578. "warna_kenderaan" => $request->warnakenderaan,
  579. "nama_kawasan" => $request->namaKawasan,
  580. "nama_taman" => $request->namaTaman,
  581. "nama_jalan" => $request->namaJalan,
  582. "no_parking" => $request->noParking,
  583. "catatan" => $request->catatan,
  584. "lokasi_kejadian" => '-',
  585. 'latlong' => $request->Latlong,
  586. 'jbkod' => $request->jabatan,
  587. 'akta' => $faulty->deed_law_id,
  588. 'seksyen_kesalahan' => $faulty->_id,
  589. 'jumlah_asal_kompaun' => $faulty->amount,
  590. 'jumlah_kemaskini_kompaun' => '',
  591. 'dikeluarkan' => $staff->_id,
  592. "status" => 'Belum Bayar',
  593. "amount_payment" => '',
  594. "receipt" => '',
  595. "modul" => '03',
  596. "penguatkuasa" => '',
  597. ];
  598. }
  599. elseif($request->jenis == 'Pelbagai_LESEN'){
  600. $compoundData = [
  601. 'jenis' => 'Parkir',
  602. 'kpd' => $kpd,
  603. 'nama' => '-',
  604. 'identity' => '-',
  605. 'alamat' => '-',
  606. "no_plate" => strtolower($request->no_plate),
  607. "no_cukai_jalan" => $request->noCukaijalan,
  608. "jenis_kenderaan" => $request->jenisKenderaan,
  609. "model_kenderaan" => $request->modelKenderaan,
  610. "warna_kenderaan" => $request->warnakenderaan,
  611. "nama_kawasan" => $request->namaKawasan,
  612. "nama_taman" => $request->namaTaman,
  613. "nama_jalan" => $request->namaJalan,
  614. "no_parking" => $request->noParking,
  615. "catatan" => $request->catatan,
  616. "lokasi_kejadian" => '-',
  617. 'latlong' => $request->Latlong,
  618. 'jbkod' => $request->jabatan,
  619. 'akta' => $faulty->deed_law_id,
  620. 'seksyen_kesalahan' => $faulty->_id,
  621. 'jumlah_asal_kompaun' => $faulty->amount,
  622. 'jumlah_kemaskini_kompaun' => '',
  623. 'dikeluarkan' => $staff->_id,
  624. "status" => 'Belum Bayar',
  625. "amount_payment" => '',
  626. "receipt" => '',
  627. "modul" => '03',
  628. "penguatkuasa" => '',
  629. ];
  630. }
  631. elseif($request->jenis == 'Pelbagai_PA'){
  632. $compoundData = [
  633. 'jenis' => 'Parkir',
  634. 'kpd' => $kpd,
  635. 'nama' => '-',
  636. 'identity' => '-',
  637. 'alamat' => '-',
  638. "no_plate" => strtolower($request->no_plate),
  639. "no_cukai_jalan" => $request->noCukaijalan,
  640. "jenis_kenderaan" => $request->jenisKenderaan,
  641. "model_kenderaan" => $request->modelKenderaan,
  642. "warna_kenderaan" => $request->warnakenderaan,
  643. "nama_kawasan" => $request->namaKawasan,
  644. "nama_taman" => $request->namaTaman,
  645. "nama_jalan" => $request->namaJalan,
  646. "no_parking" => $request->noParking,
  647. "catatan" => $request->catatan,
  648. "lokasi_kejadian" => '-',
  649. 'latlong' => $request->Latlong,
  650. 'jbkod' => $request->jabatan,
  651. 'akta' => $faulty->deed_law_id,
  652. 'seksyen_kesalahan' => $faulty->_id,
  653. 'jumlah_asal_kompaun' => $faulty->amount,
  654. 'jumlah_kemaskini_kompaun' => '',
  655. 'dikeluarkan' => $staff->_id,
  656. "status" => 'Belum Bayar',
  657. "amount_payment" => '',
  658. "receipt" => '',
  659. "modul" => '03',
  660. "penguatkuasa" => '',
  661. ];
  662. }
  663. $file = ConfidentialFile::create($fileData);
  664. $saved = $file->compound()->create($compoundData);
  665. if($saved){
  666. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  667. // if(!empty($compound)){
  668. dispatch(new UpdateCompoundPrice($kpd));
  669. // $tawaran = '';
  670. // if($compound->jumlah_kemaskini_kompaun != ''){
  671. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  672. // }else{
  673. // $tawaran = $compound->jumlah_asal_kompaun;
  674. // }
  675. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  676. array_push($data, array('kpd' => $kpd));
  677. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  678. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  679. // }
  680. }
  681. }
  682. }
  683. }
  684. /**
  685. * Display the specified resource.
  686. *
  687. * @param int $id
  688. * @return \Illuminate\Http\Response
  689. */
  690. public function show($id)
  691. {
  692. //
  693. }
  694. /**
  695. * Show the form for editing the specified resource.
  696. *
  697. * @param int $id
  698. * @return \Illuminate\Http\Response
  699. */
  700. public function edit($id)
  701. {
  702. //
  703. }
  704. /**
  705. * Update the specified resource in storage.
  706. *
  707. * @param \Illuminate\Http\Request $request
  708. * @param int $id
  709. * @return \Illuminate\Http\Response
  710. */
  711. public function update(Request $request, $id)
  712. {
  713. //
  714. }
  715. public function updateStatusPaymentViaDashboard(Request $request)
  716. {
  717. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  718. $staff = StaffDetail::find($request->current_id);
  719. if(!empty($compound) && !empty($staff)){
  720. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  721. if($compound->status != $request->status){
  722. $compound->status = $request->status;
  723. $compound->catatan_dari_admin = $request->remark;
  724. $compound->amount_payment = $request->amount;
  725. $compound->update_by = $request->current_id;
  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' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  735. '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>",
  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. if($request->status == "Berbayar"){
  747. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  748. }else{
  749. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  750. }
  751. }else{
  752. $response = [
  753. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  754. ];
  755. return response()->json($response, 200);
  756. }
  757. }else{
  758. if($request->remark != ''){
  759. $compound->catatan_dari_admin = $request->remark;
  760. $compound->update_by = $request->current_id;
  761. $compound->save();
  762. $saved = $compound->save();
  763. if($saved){
  764. $gDate = $compound->created_at->format('F Y');
  765. $historyData = [
  766. 'tarikh_kumpulan' => $gDate,
  767. ];
  768. $subHistory = [
  769. 'no_siri' => $compound->ConfidentialFile->no_siri,
  770. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  771. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  772. ];
  773. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  774. if(!empty($groupByDate)){
  775. $groupByDate->subhistory()->create($subHistory);
  776. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  777. }else{
  778. $history = History::create($historyData);
  779. $history->subhistory()->create($subHistory);
  780. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  781. }
  782. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  783. }else{
  784. $response = [
  785. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  786. ];
  787. return response()->json($response, 200);
  788. }
  789. }else{
  790. $response = [
  791. 'success' => false, 'message' => 'Tiada kemaskini!',
  792. ];
  793. return response()->json($response, 200);
  794. }
  795. }
  796. }else{
  797. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  798. $compound->status = $request->status;
  799. $compound->catatan_dari_admin = $request->remark;
  800. $compound->amount_payment = $request->amount;
  801. $compound->update_by = $request->current_id;
  802. $saved = $compound->save();
  803. if($saved){
  804. $gDate = $compound->created_at->format('F Y');
  805. $historyData = [
  806. 'tarikh_kumpulan' => $gDate,
  807. ];
  808. $subHistory = [
  809. 'no_siri' => $compound->ConfidentialFile->no_siri,
  810. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  811. '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>",
  812. ];
  813. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  814. if(!empty($groupByDate)){
  815. $groupByDate->subhistory()->create($subHistory);
  816. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  817. }else{
  818. $history = History::create($historyData);
  819. $history->subhistory()->create($subHistory);
  820. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  821. }
  822. if($request->status == "Berbayar"){
  823. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  824. }else{
  825. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  826. }
  827. }else{
  828. $response = [
  829. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  830. ];
  831. return response()->json($response, 200);
  832. }
  833. }else{
  834. if($request->remark != ''){
  835. $compound->catatan_dari_admin = $request->remark;
  836. $compound->update_by = $request->current_id;
  837. $compound->save();
  838. $saved = $compound->save();
  839. if($saved){
  840. $gDate = $compound->created_at->format('F Y');
  841. $historyData = [
  842. 'tarikh_kumpulan' => $gDate,
  843. ];
  844. $subHistory = [
  845. 'no_siri' => $compound->ConfidentialFile->no_siri,
  846. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  847. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  848. ];
  849. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  850. if(!empty($groupByDate)){
  851. $groupByDate->subhistory()->create($subHistory);
  852. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  853. }else{
  854. $history = History::create($historyData);
  855. $history->subhistory()->create($subHistory);
  856. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  857. }
  858. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  859. }else{
  860. $response = [
  861. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  862. ];
  863. return response()->json($response, 200);
  864. }
  865. }else{
  866. $response = [
  867. 'success' => false, 'message' => 'Tiada kemaskini!',
  868. ];
  869. return response()->json($response, 200);
  870. }
  871. }
  872. }
  873. }else{
  874. $response = [
  875. 'success' => false,
  876. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  877. ];
  878. return response()->json($response, 200);
  879. }
  880. }
  881. /**
  882. * Remove the specified resource from storage.
  883. *
  884. * @param int $id
  885. * @return \Illuminate\Http\Response
  886. */
  887. public function destroy($id)
  888. {
  889. //
  890. }
  891. }