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

CompoundResourceController.php 45KB

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