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

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