Dashboard sipadu mbip
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CompoundResourceController.php 45KB

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