Dashboard sipadu mbip
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CompoundResourceController.php 74KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Support\Facades\Log;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Api\BaseController;
  6. use Carbon\Carbon;
  7. use App\Model\Staff;
  8. use App\Model\StaffDetail;
  9. use App\Model\Module\Compound;
  10. use App\Model\Module\Department;
  11. use App\Model\Module\DeedLaw;
  12. use App\Model\Module\Faulty;
  13. use App\Model\Module\ConfidentialFile;
  14. use App\Model\Module\History;
  15. use App\Model\Module\SubHistory;
  16. use App\Model\Module\Memo;
  17. use App\Model\Module\Attachment;
  18. use App\Jobs\StoreCompound;
  19. use App\Jobs\StoreNotice;
  20. use App\Jobs\StoreCompoundEPBT;
  21. use App\Jobs\UpdateCompoundPrice;
  22. use App\Http\Resources\CompoundResource;
  23. class CompoundResourceController extends BaseController
  24. {
  25. /**
  26. * @var ServiceCategory
  27. */
  28. protected $compound;
  29. /**
  30. * ServiceController constructor.
  31. *
  32. * @param ServiceCategory $ServiceCategory
  33. */
  34. public function __construct(Compound $compound)
  35. {
  36. $this->compound = $compound;
  37. }
  38. /**
  39. * Display a listing of the resource.
  40. *
  41. * @return \Illuminate\Http\Response
  42. */
  43. private function searchCompoundAll($jenis,$modul,$status,$start_date,$end_date,$day3, $day7){
  44. $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
  45. $start = $dateS->copy()->startOfDay();
  46. if($end_date != ''){
  47. $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
  48. $end = $dateE->copy()->endOfDay();
  49. }else{
  50. $end = $dateS->copy()->endOfDay();
  51. }
  52. if(!empty($day3))
  53. {
  54. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start->subDays(3), $end->subDays(3)));
  55. }
  56. else if(!empty($day7))
  57. {
  58. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start->subDays(7), $end->subDays(7)));
  59. }
  60. else
  61. {
  62. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start, $end));
  63. }
  64. if($modul == 'All'){
  65. $compound = $compound;
  66. }else if($modul == '06-07'){
  67. $compound = $compound->where(function($q){
  68. // $q->where(function($query){
  69. $q->where('modul', '06')->orWhere('modul','07');
  70. // });
  71. });
  72. }else {
  73. $compound = $compound->where('modul', $modul);
  74. }
  75. if($status == 'All'){
  76. $compound = $compound;
  77. }else {
  78. $compound = $compound->where('status', $status);
  79. }
  80. return $compound;
  81. }
  82. private function searchCompoundAllWithoutDate($jenis,$modul,$status,$day3, $day7){
  83. if(!empty($day3))
  84. {
  85. $compound = Compound::where('jenis', $jenis)->where('created_at', Carbon::now()->subDays(3));
  86. }
  87. else if(!empty($day7))
  88. {
  89. $compound = Compound::where('jenis', $jenis)->where('created_at', Carbon::now()->subDays(7));
  90. }
  91. else
  92. {
  93. $compound = Compound::where('jenis', $jenis);
  94. }
  95. if($modul == 'All'){
  96. $compound = $compound;
  97. }else if($modul == '06-07'){
  98. $compound = $compound->where(function($q){
  99. $q->where(function($query){
  100. $query->where('modul', '06')->orWhere('modul','07');
  101. });
  102. });
  103. }else {
  104. $compound = $compound->where('modul', $modul);
  105. }
  106. if($status == 'All'){
  107. $compound = $compound;
  108. }else {
  109. $compound = $compound->where('status', $status);
  110. }
  111. return $compound;
  112. }
  113. private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date,$day3, $day7){
  114. if(!empty($start_date)){
  115. $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date,$day3, $day7);
  116. }else{
  117. $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status,$day3, $day7);
  118. }
  119. if($enforcer == 'All'){
  120. return $compound;
  121. }else {
  122. $compound = $compound->where('dikeluarkan', $enforcer);
  123. return $compound;
  124. }
  125. }
  126. private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$day3, $day7){
  127. $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date,$day3, $day7);
  128. if($faulty == 'All'){
  129. return $compound->whereIn('jbkod',$department);
  130. }else {
  131. $compound = $compound->where('seksyen_kesalahan', $faulty);
  132. return $compound;
  133. }
  134. }
  135. private function searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$day3, $day7){
  136. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$day3, $day7);
  137. if(!empty($plate_no)){
  138. $compound = $compound->where('no_plate',$plate_no);
  139. return $compound;
  140. }else{
  141. return $compound;
  142. }
  143. }
  144. private function searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$day3, $day7){
  145. $compound = $this->searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$day3, $day7);
  146. if(!empty($kpd)){
  147. $compound = $compound->where('kpd',$kpd);
  148. return $compound;
  149. }else{
  150. $compound = $compound->whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal']);
  151. return $compound;
  152. }
  153. }
  154. private function searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$day3, $day7){
  155. $compound = $this->searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$day3, $day7);
  156. if(!empty($company_no)){
  157. $compound = $compound->where('no_daftar_syarikat','LIKE',$company_no);
  158. return $compound;
  159. }else{
  160. return $compound;
  161. }
  162. }
  163. private function searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$day3, $day7){
  164. $compound = $this->searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$day3, $day7);
  165. if(!empty($nric)){
  166. $compound = $compound->where('identity',$nric);
  167. return $compound;
  168. }else{
  169. return $compound;
  170. }
  171. }
  172. private function searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$day3, $day7){
  173. $compound = $this->searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$day3, $day7);
  174. if(!empty($license)){
  175. $compound = $compound->where('no_akaun_lesen', 'exists', true)->where('no_akaun_lesen',$license);
  176. return $compound;
  177. }else{
  178. return $compound;
  179. }
  180. }
  181. private function searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$day3, $day7){
  182. $compound = $this->searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$day3, $day7);
  183. if(!empty($namaP)){
  184. $compound = $compound->where('nama', 'LIKE', "%{$namaP}%");
  185. return $compound;
  186. }else{
  187. return $compound;
  188. }
  189. }
  190. private function searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name,$day3, $day7){
  191. $compound = $this->searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$day3, $day7);
  192. if(!empty($company_name)){
  193. $compound = $compound->where('nama_syarikat', 'exists', true)->where('nama_syarikat', 'LIKE', '%{$company_name%}');
  194. return $compound;
  195. }else{
  196. return $compound;
  197. }
  198. }
  199. public function index(Request $request)
  200. {
  201. // $per_page = '';
  202. // $kpd = '';
  203. // $modul = '02';
  204. // $status = 'All';
  205. // $jenis = 'Pelbagai_JPB';
  206. // if(!empty($request->department)){
  207. // $department = array (
  208. // 0 => '5df355f891d6e66b9c5e626d',
  209. // 1 => '5df721c5cde7fd741433c6b2',
  210. // 2 => '5df722a24636f4594f4a3c3d',
  211. // 3 => '5f17a31795dbfd3320761bfe',
  212. // 4 => '5f3b872fea58cb3c1b0e7b8d',
  213. // );
  214. // }else {
  215. // $department = [];
  216. // }
  217. // // $start_date = '';
  218. // // $end_date = '';
  219. // $start_date = '2020-08-29';
  220. // $end_date = '2020-08-29';
  221. // $enforcer = 'All';
  222. // $faulty = 'All';
  223. // $plate_no = strtolower('');
  224. // $company_no = strtolower('');
  225. // $nric = '';
  226. // $license = '';
  227. // $namaP = '';
  228. // $company_name = '';
  229. // $day3 = 3;
  230. // $day7 = '';
  231. /////////////////////////////////////////////////////////////////////////////////
  232. $per_page = $request->per_page;
  233. $kpd = $request->kpd;
  234. $modul = $request->modul;
  235. $status = $request->status;
  236. $jenis = $request->type;
  237. if(!empty($request->department)){
  238. $department = json_decode($request->department);
  239. }else {
  240. $department = [];
  241. }
  242. $start_date = $request->start_date;
  243. $end_date = $request->end_date;
  244. $enforcer = $request->enforcer;
  245. $faulty = $request->faulty;
  246. $plate_no = strtolower($request->plate_no);
  247. $company_no = strtolower($request->company_no);
  248. $nric = $request->nric;
  249. $license = $request->license;
  250. $namaP = $request->nameP;
  251. $company_name = $request->company_name;
  252. $day3='';
  253. $day7='';
  254. if ($request->has('day3')) {
  255. $day3 = $request->day3; //has() checks if param exist and filled
  256. }
  257. if ($request->has('day7')) {
  258. $day3 = $request->day7; //has() checks if param exist and filled
  259. }
  260. // if (!empty($start_date)) {
  261. // }
  262. $nested_data = array();
  263. $compound = $this->searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name, $day3, $day7)->orderBy('created_at','ASC')->get();
  264. // info($compound);
  265. return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
  266. ->addColumn('index', function($row) {
  267. $curr = Carbon::now();
  268. $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
  269. if($curr->diffInDays($dtC) <= 3){
  270. $html = 'New';
  271. }else{ $html = ''; }
  272. return $html;
  273. })->addColumn('status_kemaskini', function($row) {
  274. $data = '';
  275. if($row['status'] == 'Berbayar'){
  276. if ($row['modul'] == '02') {
  277. $data = '<b>Selesai</b><div style="margin-top: 8px"><span></span><br/></div>';
  278. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  279. }
  280. else{
  281. $data = '<b>'.$row['status'].'</b><div style="margin-top: 8px"><span>Bayaran: </span><br/>';
  282. $data .= 'RM '.$row['amount_payment'].'</div>';
  283. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  284. }
  285. if($row['updated_by'] !== null ){
  286. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  287. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  288. }else {
  289. if(!empty($row['tarikh_bayar']) && $row['tarikh_bayar'] != ''){
  290. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  291. $data .= $row['tarikh_bayar'].' <br/>'.$row['updates_by'].'</div>';
  292. }else {
  293. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  294. $data .= $row['updated_at'].' <br/>'.$row['updates_by'].'</div>';
  295. }
  296. }
  297. }else if($row['status'] == 'Belum Bayar' && $row['updated_by'] !== null){
  298. $data = '<b>'.$row['status'].'</b>';
  299. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  300. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  301. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  302. }else if($row['status'] == 'Batal' && $row['updated_by'] !== null){
  303. $data = '<b>'.$row['status'].'</b>';
  304. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  305. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  306. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  307. }else if($row['status'] == 'Buang' && $row['updated_by'] !== null){
  308. $data = '<b>'.$row['status'].'</b>';
  309. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  310. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  311. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  312. }
  313. else
  314. {
  315. $data = $row['status'];
  316. }
  317. return $data;
  318. })->addColumn('kesalahan', function($row) {
  319. $data = '<b>Seksyen '.$row['faulty_skter'].'</b><br/>'.$row['faulty_name'];
  320. return $data;
  321. })->rawColumns(['index','status_kemaskini','kesalahan'])->make(true);
  322. }
  323. /**
  324. * Show the form for creating a new resource.
  325. *
  326. * @return \Illuminate\Http\Response
  327. */
  328. public function generateCompoundNumber($jenis, $tag)
  329. {
  330. //check if theres no 001, start fresh with 0001
  331. if (empty(Compound::where('jenis', $jenis)->where('kpd', $tag.'0001')->first())) {
  332. $kpd = '0001';
  333. }
  334. else{
  335. //check the lastest compound number stored in dbase filtered by jenis
  336. $compound = Compound::where('jenis', $jenis)->withTrashed()->latest()->first();
  337. //sanitize compound number to return only integer
  338. $kpd = filter_var($compound['kpd'], FILTER_SANITIZE_NUMBER_INT);
  339. //compulsory increment to store new compound number, WHILE number is found, keep looping
  340. do{
  341. (int)$kpd += 1;
  342. //add 0s at the fornt if number is less than 1000
  343. if ((strlen((string) $kpd)) == 1) {
  344. $kpd = '000'.$kpd;
  345. }elseif ((strlen((string)$kpd)) == 2){
  346. $kpd = '00'.$kpd;
  347. }elseif ((strlen((string)$kpd )) == 3) {
  348. $kpd = '0'.$kpd;
  349. }
  350. }while(!empty(Compound::where('jenis', $jenis)->where('kpd', $tag.$kpd)->first()));
  351. }
  352. return $kpd;
  353. }
  354. /**
  355. * Store a created compound from notice.
  356. *
  357. * @param \Illuminate\Http\Request $request
  358. * @return \Illuminate\Http\Response
  359. */
  360. public function store(Request $request)
  361. {
  362. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  363. if(empty($staff)){
  364. return $this->sendError('Invalid', 'Staff not existed');
  365. }else {
  366. $saved ='';
  367. $kpd = '';
  368. $no_siri = '';
  369. $data = array();
  370. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  371. if($request->jenis == 'Parkir')
  372. {
  373. if(!empty($faulty)){
  374. $countKPD = $this->compound->withTrashed()->count();
  375. do {
  376. $countKPD = $countKPD + 1;
  377. } while (!empty(Compound::where("kpd", "=", 'KP'.$countKPD)->first()));
  378. $kpd = 'KP'.$countKPD;
  379. $no_siri = date('yn').'-'.$countKPD;
  380. $fileData = [
  381. 'no_siri' => $no_siri,
  382. ];
  383. //only for compound parkir
  384. $compoundData = [
  385. 'jenis' => 'Parkir',
  386. 'kpd' => 'KPD'.$kpd,
  387. 'nama' => '-',
  388. 'identity' => '-',
  389. 'alamat' => '-',
  390. "no_plate" => strtolower($request->no_plate),
  391. "no_cukai_jalan" => $request->noCukaijalan,
  392. "jenis_kenderaan" => $request->jenisKenderaan,
  393. "model_kenderaan" => $request->modelKenderaan,
  394. "warna_kenderaan" => $request->warnakenderaan,
  395. "nama_kawasan" => $request->namaKawasan,
  396. "nama_taman" => $request->namaTaman,
  397. "nama_jalan" => $request->namaJalan,
  398. "no_parking" => $request->noParking,
  399. "catatan" => $request->catatan,
  400. "lokasi_kejadian" => '-',
  401. 'latlong' => $request->Latlong,
  402. 'jbkod' => $request->jabatan,
  403. 'akta' => $faulty->deed_law_id,
  404. 'seksyen_kesalahan' => $faulty->_id,
  405. 'jumlah_asal_kompaun' => $faulty->amount,
  406. 'jumlah_kemaskini_kompaun' => '-',
  407. 'dikeluarkan' => $staff->_id,
  408. "status" => 'Belum Bayar',
  409. "amount_payment" => '-',
  410. "receipt" => '-',
  411. "modul" => '03',
  412. "penguatkuasa" => '-',
  413. "cpn_created" => Carbon::now()->toDateTimeString(),
  414. ];
  415. $file = ConfidentialFile::create($fileData);
  416. $saved = $file->compound()->create($compoundData);
  417. }
  418. }elseif(($request->jenis == 'Pelbagai_KT') || ($request->jenis == 'Pelbagai_JPB') || ($request->jenis == 'Pelbagai_PA') || ($request->jenis == 'Pelbagai_LESEN')){
  419. $kpd = $request->kpd;
  420. $compound = Compound::where('jenis', $request->jenis)->where('kpd', $kpd)->first();
  421. info($compound);
  422. if (!empty($compound)) {
  423. $saved = '';
  424. if($compound->modul != '03')
  425. {
  426. if($request->jenis == 'Pelbagai_KT'){
  427. $compound->jenis = $request->jenis;
  428. $compound->nama = $request->namaP;
  429. $compound->identity = $request->noIc;
  430. $compound->nama_syarikat = $request->namaS;
  431. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  432. $compound->alamat = $request->alamat;
  433. $compound->no_plate = $request->no_plate;
  434. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  435. // $compound->nama_kawasan = $request->namaKawasan;
  436. // $compound->nama_taman = $request->namaTaman;
  437. // $compound->nama_jalan = $request->namaJalan;
  438. $compound->catatan = $request->catatan;
  439. $compound->latlong = $request->Latlong;
  440. // $compound->akta = $faulty->deed_law_id;
  441. // $compound->seksyen_kesalahan = $faulty->_id;
  442. // $compound->jumlah_asal_kompaun = $faulty->amount;
  443. $compound->dikeluarkan_ = $staff->_id;
  444. $compound->status = 'Belum Bayar';
  445. $compound->modul = '03';
  446. $compound->no_telefon = $request->tel;
  447. $compound->no_akaun_lesen = $request->lesen;
  448. $compound->cpn_created = Carbon::now()->toDateTimeString();
  449. }elseif($request->jenis == 'Pelbagai_JPB'){
  450. $compound->jenis = $request->jenis;
  451. $compound->nama = $request->namaP;
  452. $compound->identity = $request->noIc;
  453. $compound->nama_syarikat = $request->namaS;
  454. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  455. $compound->alamat = $request->alamat;
  456. $compound->no_plate = $request->no_plate;
  457. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  458. // $compound->nama_kawasan => $request->namaKawasan;
  459. // $compound->nama_taman => $request->namaTaman;
  460. // $compound->nama_jalan => $request->namaJalan;
  461. $compound->catatan = $request->catatan;
  462. $compound->latlong = $request->Latlong;
  463. // $compound->akta => $faulty->deed_law_id;
  464. // $compound->seksyen_kesalahan => $faulty->_id;
  465. // $compound->jumlah_asal_kompaun => $faulty->amount;
  466. $compound->dikeluarkan_ = $staff->_id;
  467. $compound->status = 'Belum Bayar';
  468. $compound->modul = '03';
  469. $compound->no_telefon = $request->tel;
  470. $compound->no_akaun_lesen = $request->lesen;
  471. $compound->cpn_created = Carbon::now()->toDateTimeString();
  472. }elseif($request->jenis == 'Pelbagai_PA'){
  473. $compound->jenis = $request->jenis;
  474. $compound->nama = $request->namaP;
  475. $compound->identity = $request->noIc;
  476. $compound->nama_syarikat = $request->namaS;
  477. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  478. $compound->alamat = $request->alamat;
  479. $compound->no_plate = $request->no_plate;
  480. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  481. // $compound->nama_kawasan = $request->namaKawasan;
  482. // $compound->nama_taman = $request->namaTaman;
  483. // $compound->nama_jalan = $request->namaJalan;
  484. $compound->catatan = $request->catatan;
  485. $compound->latlong = $request->Latlong;
  486. // $compound->akta = $faulty->deed_law_id;
  487. // $compound->seksyen_kesalahan = $faulty->_id;
  488. // $compound->jumlah_asal_kompaun = $faulty->amount;
  489. $compound->dikeluarkan_ = $staff->_id;
  490. $compound->status = 'Belum Bayar';
  491. $compound->modul = '03';
  492. $compound->no_telefon = $request->tel;
  493. $compound->no_akaun_lesen = $request->lesen;
  494. $compound->bil_haiwan = $request->lesen;
  495. $compound->cpn_created = Carbon::now()->toDateTimeString();
  496. }elseif($request->jenis == 'Pelbagai_LESEN'){
  497. $compound->jenis = $request->jenis;
  498. $compound->nama = $request->namaP;
  499. $compound->identity = $request->noIc;
  500. $compound->nama_syarikat = $request->namaS;
  501. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  502. $compound->alamat = $request->alamat;
  503. $compound->no_plate = $request->no_plate;
  504. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  505. // $compound->nama_kawasan = $request->namaKawasan;
  506. // $compound->nama_taman = $request->namaTaman;
  507. // $compound->nama_jalan = $request->namaJalan;
  508. $compound->catatan = $request->catatan;
  509. $compound->latlong = $request->Latlong;
  510. // $compound->akta = $faulty->deed_law_id;
  511. // $compound->seksyen_kesalahan = $faulty->_id;
  512. // $compound->jumlah_asal_kompaun = $faulty->amount;
  513. $compound->dikeluarkan_ = $staff->_id;
  514. $compound->status = 'Belum Bayar';
  515. $compound->modul = '03';
  516. $compound->no_telefon = $request->tel;
  517. $compound->no_akaun_lesen = $request->lesen;
  518. $compound->cpn_created = Carbon::now()->toDateTimeString();
  519. }
  520. $saved = $compound->save();
  521. }
  522. else
  523. {
  524. return $this->sendResponse('', 'Kompaun ini telah dikeluarkan!');
  525. }
  526. if($saved){
  527. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  528. // if(!empty($compound)){
  529. dispatch(new UpdateCompoundPrice($kpd));
  530. // $tawaran = '';
  531. // if($compound->jumlah_kemaskini_kompaun != ''){
  532. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  533. // }else{
  534. // $tawaran = $compound->jumlah_asal_kompaun;
  535. // }
  536. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  537. array_push($data, array('kpd' => $kpd));
  538. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  539. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  540. // }
  541. }
  542. }
  543. else{
  544. return $this->sendResponse('', 'Kompaun ini tidak dijumpai!');
  545. }
  546. }
  547. }
  548. }
  549. /**
  550. *
  551. * Store a newly created notice
  552. *
  553. **/
  554. public function storeNotice(Request $request)
  555. {
  556. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  557. if(empty($staff)){
  558. return $this->sendError('Invalid', 'Staff not existed');
  559. }else {
  560. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  561. if(!empty($faulty)){
  562. $data = array();
  563. $kpd = '';
  564. $no_siri ='';
  565. // $countKPD = $this->compound->withTrashed()->count(); //for parking numbering
  566. // do {
  567. // $kpd = $kpd + 1;
  568. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  569. // $kpd = 'KP'.$countKPD;
  570. // $no_siri = date('yn').'-'.$countKPD;
  571. // $fileData = [
  572. // 'no_siri' => $no_siri,
  573. // ];
  574. if($request->jenis == 'Parkir'){
  575. //for compound numbering
  576. $countKPD = $this->compound->withTrashed()->count();
  577. $no_siri = date('yn').'-'.$countKPD.'-0';
  578. $compoundData = [
  579. 'jenis' => 'Parkir',
  580. 'kpd' => 'KPD'.$countKPD,
  581. 'nama' => '-',
  582. 'identity' => '-',
  583. 'alamat' => '-',
  584. "no_plate" => strtolower($request->no_plate),
  585. "no_cukai_jalan" => $request->noCukaijalan,
  586. "jenis_kenderaan" => $request->jenisKenderaan,
  587. "model_kenderaan" => $request->modelKenderaan,
  588. "warna_kenderaan" => $request->warnakenderaan,
  589. "nama_kawasan" => $request->namaKawasan,
  590. "nama_taman" => $request->namaTaman,
  591. "nama_jalan" => $request->namaJalan,
  592. "no_parking" => $request->noParking,
  593. "catatan" => $request->catatan,
  594. "lokasi_kejadian" => '-',
  595. 'latlong' => $request->Latlong,
  596. 'jbkod' => $request->jabatan,
  597. 'akta' => $faulty->deed_law_id,
  598. 'seksyen_kesalahan' => $faulty->_id,
  599. 'jumlah_asal_kompaun' => $faulty->amount,
  600. 'jumlah_kemaskini_kompaun' => '-',
  601. 'dikeluarkan' => $staff->_id,
  602. "status" => 'Belum Bayar',
  603. "amount_payment" => '-',
  604. "receipt" => '-',
  605. "modul" => $request->modul,
  606. "penguatkuasa" => '-',
  607. "notis_created" => Carbon::now()->toDateTimeString(),
  608. ];
  609. }elseif($request->jenis == 'Pelbagai_KT'){
  610. $kpd = $this->generateCompoundNumber($request->jenis, 'KT');
  611. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  612. $compoundData = [
  613. 'jenis' => $request->jenis,
  614. 'kpd' => 'KT'.$kpd,
  615. 'non' => 'NKG'.$kpd,
  616. 'nama' => $request->namaP,
  617. 'identity' => $request->noIc,
  618. 'nama_syarikat' => $request->namaS,
  619. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  620. 'alamat' => $request->alamat,
  621. "no_plate" => $request->no_plate,
  622. "no_cukai_jalan" => $request->no_cukai_jalan,
  623. "nama_kawasan" => $request->namaKawasan,
  624. "nama_taman" => $request->namaTaman,
  625. "nama_jalan" => $request->namaJalan,
  626. "catatan" => $request->catatan,
  627. "lokasi_kejadian" => '-',
  628. 'latlong' => $request->Latlong,
  629. 'jbkod' => $request->jabatan,
  630. 'akta' => $faulty->deed_law_id,
  631. 'seksyen_kesalahan' => $faulty->_id,
  632. 'jumlah_asal_kompaun' => $faulty->amount,
  633. 'jumlah_kemaskini_kompaun' => '-',
  634. 'dikeluarkan' => $staff->_id,
  635. "status" => 'Belum Bayar',
  636. "amount_payment" => '-',
  637. "receipt" => '-',
  638. "modul" => $request->modul,
  639. "penguatkuasa" => '-',
  640. "no_telefon" => $request->tel,
  641. "no_akaun_lesen" => $request->lesen,
  642. "maklumat_tambahan" => '-',
  643. "tindakan" => $request->tindakan,
  644. "tempoh" => $request->tempoh,
  645. "notis_created" => Carbon::now()->toDateTimeString(),
  646. ];
  647. }elseif($request->jenis == 'Pelbagai_JPB'){
  648. $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  649. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  650. $compoundData = [
  651. 'jenis' => $request->jenis,
  652. 'kpd' => 'JPB'.$kpd,
  653. 'non' => 'NMH'.$kpd,
  654. 'nama' => $request->namaP,
  655. 'identity' => $request->noIc,
  656. 'nama_syarikat' => $request->namaS,
  657. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  658. 'alamat' => $request->alamat,
  659. "no_plate" => $request->no_plate,
  660. "no_cukai_jalan" => $request->no_cukai_jalan,
  661. "nama_kawasan" => $request->namaKawasan,
  662. "nama_taman" => $request->namaTaman,
  663. "nama_jalan" => $request->namaJalan,
  664. "catatan" => $request->catatan,
  665. "lokasi_kejadian" => '-',
  666. 'latlong' => $request->Latlong,
  667. 'jbkod' => $request->jabatan,
  668. 'akta' => $faulty->deed_law_id,
  669. 'seksyen_kesalahan' => $faulty->_id,
  670. 'jumlah_asal_kompaun' => $faulty->amount,
  671. 'jumlah_kemaskini_kompaun' => '-',
  672. 'dikeluarkan' => $staff->_id,
  673. "status" => 'Belum Bayar',
  674. "amount_payment" => '-',
  675. "receipt" => '-',
  676. "modul" => $request->modul,
  677. "penguatkuasa" => '-',
  678. "no_telefon" => $request->tel,
  679. "no_akaun_lesen" => $request->lesen,
  680. "maklumat_tambahan" => '-',
  681. "tindakan" => $request->tindakan,
  682. "tempoh" => $request->tempoh,
  683. "notis_created" => Carbon::now()->toDateTimeString(),
  684. ];
  685. }
  686. elseif($request->jenis == 'Pelbagai_LESEN'){
  687. $kpd = $this->generateCompoundNumber($request->jenis, 'NHN');
  688. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-3';
  689. $compoundData = [
  690. 'jenis' => $request->jenis,
  691. 'kpd' => 'NHN'.$kpd,
  692. 'non' => 'NHN'.$kpd,
  693. 'nama' => $request->namaP,
  694. 'identity' => $request->noIc,
  695. 'nama_syarikat' => $request->namaS,
  696. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  697. 'alamat' => $request->alamat,
  698. "no_plate" => $request->no_plate,
  699. "no_cukai_jalan" => $request->no_cukai_jalan,
  700. "nama_kawasan" => $request->namaKawasan,
  701. "nama_taman" => $request->namaTaman,
  702. "nama_jalan" => $request->namaJalan,
  703. "catatan" => $request->catatan,
  704. "lokasi_kejadian" => '-',
  705. 'latlong' => $request->Latlong,
  706. 'jbkod' => $request->jabatan,
  707. 'akta' => $faulty->deed_law_id,
  708. 'seksyen_kesalahan' => $faulty->_id,
  709. 'jumlah_asal_kompaun' => $faulty->amount,
  710. 'jumlah_kemaskini_kompaun' => '-',
  711. 'dikeluarkan' => $staff->_id,
  712. "status" => 'Belum Bayar',
  713. "amount_payment" => '-',
  714. "receipt" => '-',
  715. "modul" => $request->modul,
  716. "penguatkuasa" => '-',
  717. "no_telefon" => $request->tel,
  718. "no_akaun_lesen" => $request->lesen,
  719. "maklumat_tambahan" => '-',
  720. "notis_created" => Carbon::now()->toDateTimeString(),
  721. ];
  722. }
  723. elseif($request->jenis == 'Pelbagai_PA'){
  724. $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  725. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-4';
  726. $compoundData = [
  727. 'jenis' => $request->jenis,
  728. 'kpd' => 'PA'.$kpd,
  729. 'non' => 'PA'.$kpd,
  730. 'nama' => $request->namaP,
  731. 'identity' => $request->noIc,
  732. 'nama_syarikat' => $request->namaS,
  733. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  734. 'alamat' => $request->alamat,
  735. "no_plate" => $request->no_plate,
  736. "no_cukai_jalan" => $request->no_cukai_jalan,
  737. "nama_kawasan" => $request->namaKawasan,
  738. "nama_taman" => $request->namaTaman,
  739. "nama_jalan" => $request->namaJalan,
  740. "catatan" => $request->catatan,
  741. "lokasi_kejadian" => '-',
  742. 'latlong' => $request->Latlong,
  743. 'jbkod' => $request->jabatan,
  744. 'akta' => $faulty->deed_law_id,
  745. 'seksyen_kesalahan' => $faulty->_id,
  746. 'jumlah_asal_kompaun' => $faulty->amount,
  747. 'jumlah_kemaskini_kompaun' => '-',
  748. 'dikeluarkan' => $staff->_id,
  749. "status" => 'Belum Bayar',
  750. "amount_payment" => '-',
  751. "receipt" => '-',
  752. "modul" => $request->modul,
  753. "penguatkuasa" => '-',
  754. "no_telefon" => $request->tel,
  755. "no_akaun_lesen" => $request->lesen,
  756. "maklumat_tambahan" => '-',
  757. "bil_haiwan" => $request->bil_haiwan,
  758. "notis_created" => Carbon::now()->toDateTimeString(),
  759. ];
  760. }
  761. $fileData = [
  762. 'no_siri' => $no_siri,
  763. ];
  764. $file = ConfidentialFile::create($fileData);
  765. $saved = $file->compound()->create($compoundData);
  766. if($saved){
  767. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  768. // if(!empty($compound)){
  769. dispatch(new UpdateCompoundPrice($kpd));
  770. // $tawaran = '';
  771. // if($compound->jumlah_kemaskini_kompaun != ''){
  772. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  773. // }else{
  774. // $tawaran = $compound->jumlah_asal_kompaun;
  775. // }
  776. $this->dispatch(new StoreNotice($request->all(), $kpd, $staff->_id, $no_siri));
  777. array_push($data, array('kpd' => $kpd));
  778. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  779. // }
  780. }
  781. }
  782. }
  783. }
  784. /**
  785. * Store a newly created compound (parkir, KT, JPB).
  786. *
  787. * @param \Illuminate\Http\Request $request
  788. * @return \Illuminate\Http\Response
  789. */
  790. public function storeNewCompound(Request $request)
  791. {
  792. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  793. if(empty($staff)){
  794. return $this->sendError('Invalid', 'Staff not existed');
  795. }else {
  796. $data = array();
  797. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  798. if(!empty($faulty)){
  799. $kpd = '';
  800. $no_siri ='';
  801. // $countKPD = $this->compound->withTrashed()->count();
  802. // do {
  803. // $countKPD = $countKPD + 1;
  804. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  805. // $kpd = $countKPD;
  806. // $no_siri = date('yn').'-'.$countKPD;
  807. // $fileData = [
  808. // 'no_siri' => $no_siri,
  809. // ];
  810. if($request->jenis == 'Parkir')
  811. {
  812. //for compound numbering
  813. $countKPD = $this->compound->withTrashed()->count();
  814. $no_siri = date('yn').'-'.$countKPD.'-0';
  815. //only for compound parkir
  816. $compoundData = [
  817. 'jenis' => 'Parkir',
  818. 'kpd' => 'KPD'.$countKPD,
  819. 'nama' => '-',
  820. 'identity' => '-',
  821. 'alamat' => '-',
  822. "no_plate" => strtolower($request->no_plate),
  823. "no_cukai_jalan" => $request->noCukaijalan,
  824. "jenis_kenderaan" => $request->jenisKenderaan,
  825. "model_kenderaan" => $request->modelKenderaan,
  826. "warna_kenderaan" => $request->warnakenderaan,
  827. "nama_kawasan" => $request->namaKawasan,
  828. "nama_taman" => $request->namaTaman,
  829. "nama_jalan" => $request->namaJalan,
  830. "no_parking" => $request->noParking,
  831. "catatan" => $request->catatan,
  832. "lokasi_kejadian" => '-',
  833. 'latlong' => $request->Latlong,
  834. 'jbkod' => $request->jabatan,
  835. 'akta' => $faulty->deed_law_id,
  836. 'seksyen_kesalahan' => $faulty->_id,
  837. 'jumlah_asal_kompaun' => $faulty->amount,
  838. 'jumlah_kemaskini_kompaun' => '-',
  839. 'dikeluarkan' => $staff->_id,
  840. "status" => 'Belum Bayar',
  841. "amount_payment" => '-',
  842. "receipt" => '-',
  843. "modul" => '03',
  844. "penguatkuasa" => '-',
  845. "cpn_created" => Carbon::now()->toDateTimeString(),
  846. ];
  847. }
  848. if ($request->jenis == 'Pelbagai_KT') {
  849. $kpd = $this->generateCompoundNumber($request->jenis, 'KT');
  850. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  851. $compoundData = [
  852. 'jenis' => $request->jenis,
  853. 'kpd' => 'KT'.$kpd,
  854. 'nama' => $request->namaP,
  855. 'identity' => $request->noIc,
  856. 'nama_syarikat' => $request->namaS,
  857. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  858. 'alamat' => $request->alamat,
  859. "no_plate" => $request->no_plate,
  860. "no_cukai_jalan" => $request->no_cukai_jalan,
  861. "nama_kawasan" => $request->namaKawasan,
  862. "nama_taman" => $request->namaTaman,
  863. "nama_jalan" => $request->namaJalan,
  864. "catatan" => $request->catatan,
  865. "lokasi_kejadian" => '-',
  866. 'latlong' => $request->Latlong,
  867. 'jbkod' => $request->jabatan,
  868. 'akta' => $faulty->deed_law_id,
  869. 'seksyen_kesalahan' => $faulty->_id,
  870. 'jumlah_asal_kompaun' => $faulty->amount,
  871. 'jumlah_kemaskini_kompaun' => '-',
  872. 'dikeluarkan' => $staff->_id,
  873. "status" => 'Belum Bayar',
  874. "amount_payment" => '-',
  875. "receipt" => '-',
  876. "modul" => $request->modul,
  877. "penguatkuasa" => '-',
  878. "no_telefon" => $request->tel,
  879. "no_akaun_lesen" => $request->lesen,
  880. "maklumat_tambahan" => '-',
  881. "tindakan" => '-',
  882. "tempoh" => '-',
  883. "cpn_created" => Carbon::now()->toDateTimeString(),
  884. ];
  885. }
  886. elseif ($request->jenis == 'Pelbagai_JPB') {
  887. $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  888. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  889. $compoundData = [
  890. 'jenis' => $request->jenis,
  891. 'kpd' => 'JPB'.$kpd,
  892. 'nama' => $request->namaP,
  893. 'identity' => $request->noIc,
  894. 'nama_syarikat' => $request->namaS,
  895. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  896. 'alamat' => $request->alamat,
  897. "no_plate" => $request->no_plate,
  898. "no_cukai_jalan" => $request->no_cukai_jalan,
  899. "nama_kawasan" => $request->namaKawasan,
  900. "nama_taman" => $request->namaTaman,
  901. "nama_jalan" => $request->namaJalan,
  902. "catatan" => $request->catatan,
  903. "lokasi_kejadian" => '-',
  904. 'latlong' => $request->Latlong,
  905. 'jbkod' => $request->jabatan,
  906. 'akta' => $faulty->deed_law_id,
  907. 'seksyen_kesalahan' => $faulty->_id,
  908. 'jumlah_asal_kompaun' => $faulty->amount,
  909. 'jumlah_kemaskini_kompaun' => '-',
  910. 'dikeluarkan' => $staff->_id,
  911. "status" => 'Belum Bayar',
  912. "amount_payment" => '-',
  913. "receipt" => '-',
  914. "modul" => $request->modul,
  915. "penguatkuasa" => '-',
  916. "no_telefon" => $request->tel,
  917. "no_akaun_lesen" => $request->lesen,
  918. "maklumat_tambahan" => '-',
  919. "tindakan" => '-',
  920. "tempoh" => '-',
  921. "cpn_created" => Carbon::now()->toDateTimeString(),
  922. ];
  923. }
  924. elseif ($request->jenis == 'Pelbagai_LESEN') {
  925. $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  926. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-3';
  927. $compoundData = [
  928. 'jenis' => $request->jenis,
  929. 'kpd' => 'NHN'.$kpd,
  930. 'nama' => $request->namaP,
  931. 'identity' => $request->noIc,
  932. 'nama_syarikat' => $request->namaS,
  933. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  934. 'alamat' => $request->alamat,
  935. "no_plate" => $request->no_plate,
  936. "no_cukai_jalan" => $request->no_cukai_jalan,
  937. "nama_kawasan" => $request->namaKawasan,
  938. "nama_taman" => $request->namaTaman,
  939. "nama_jalan" => $request->namaJalan,
  940. "catatan" => $request->catatan,
  941. "lokasi_kejadian" => '-',
  942. 'latlong' => $request->Latlong,
  943. 'jbkod' => $request->jabatan,
  944. 'akta' => $faulty->deed_law_id,
  945. 'seksyen_kesalahan' => $faulty->_id,
  946. 'jumlah_asal_kompaun' => $faulty->amount,
  947. 'jumlah_kemaskini_kompaun' => '-',
  948. 'dikeluarkan' => $staff->_id,
  949. "status" => 'Belum Bayar',
  950. "amount_payment" => '-',
  951. "receipt" => '-',
  952. "modul" => $request->modul,
  953. "penguatkuasa" => '-',
  954. "no_telefon" => $request->tel,
  955. "no_akaun_lesen" => $request->lesen,
  956. "maklumat_tambahan" => '-',
  957. "cpn_created" => Carbon::now()->toDateTimeString(),
  958. ];
  959. }
  960. else if($request->jenis == 'Pelbagai_PA'){
  961. $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  962. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-4';
  963. $compoundData = [
  964. 'jenis' => $request->jenis,
  965. 'kpd' => 'PA'.$kpd,
  966. 'nama' => $request->namaP,
  967. 'identity' => $request->noIc,
  968. 'nama_syarikat' => $request->namaS,
  969. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  970. 'alamat' => $request->alamat,
  971. "no_plate" => $request->no_plate,
  972. "no_cukai_jalan" => $request->no_cukai_jalan,
  973. "nama_kawasan" => $request->namaKawasan,
  974. "nama_taman" => $request->namaTaman,
  975. "nama_jalan" => $request->namaJalan,
  976. "catatan" => $request->catatan,
  977. "lokasi_kejadian" => '-',
  978. 'latlong' => $request->Latlong,
  979. 'jbkod' => $request->jabatan,
  980. 'akta' => $faulty->deed_law_id,
  981. 'seksyen_kesalahan' => $faulty->_id,
  982. 'jumlah_asal_kompaun' => $faulty->amount,
  983. 'jumlah_kemaskini_kompaun' => '-',
  984. 'dikeluarkan' => $staff->_id,
  985. "status" => 'Belum Bayar',
  986. "amount_payment" => '-',
  987. "receipt" => '-',
  988. "modul" => $request->modul,
  989. "penguatkuasa" => '-',
  990. "no_telefon" => $request->tel,
  991. "no_akaun_lesen" => $request->lesen,
  992. "maklumat_tambahan" => '-',
  993. "bil_haiwan" => $request->bil_haiwan,
  994. "cpn_created" => Carbon::now()->toDateTimeString(),
  995. ];
  996. }
  997. $fileData = [
  998. 'no_siri' => $no_siri,
  999. ];
  1000. $file = ConfidentialFile::create($fileData);
  1001. $saved = $file->compound()->create($compoundData);
  1002. if($saved){
  1003. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  1004. // if(!empty($compound)){
  1005. dispatch(new UpdateCompoundPrice($kpd));
  1006. // $tawaran = '';
  1007. // if($compound->jumlah_kemaskini_kompaun != ''){
  1008. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  1009. // }else{
  1010. // $tawaran = $compound->jumlah_asal_kompaun;
  1011. // }
  1012. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  1013. array_push($data, array('kpd' => $kpd));
  1014. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  1015. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  1016. }
  1017. }
  1018. return $this->sendResponse('Tidak Berjaya!', 'Kesalahan tidak dijumpai!');
  1019. }
  1020. }
  1021. /**
  1022. * Display the specified resource.
  1023. *
  1024. * @param int $id
  1025. * @return \Illuminate\Http\Response
  1026. */
  1027. public function show($id)
  1028. {
  1029. //
  1030. }
  1031. /**
  1032. * Show the form for editing the specified resource.
  1033. *
  1034. * @param int $id
  1035. * @return \Illuminate\Http\Response
  1036. */
  1037. public function edit($id)
  1038. {
  1039. //
  1040. }
  1041. /**
  1042. * Update the specified resource in storage.
  1043. *
  1044. * @param \Illuminate\Http\Request $request
  1045. * @param int $id
  1046. * @return \Illuminate\Http\Response
  1047. */
  1048. public function update(Request $request, $id)
  1049. {
  1050. //
  1051. }
  1052. public function updateStatusNoticeViaDashboard(Request $request)
  1053. {
  1054. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1055. $staff = StaffDetail::find($request->current_id);
  1056. if(!empty($compound) && !empty($staff)){
  1057. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1058. if($compound->status != $request->status){
  1059. $compound->status = $request->status;
  1060. $compound->catatan_dari_admin = $request->remark;
  1061. $compound->update_by = $request->current_id;
  1062. $saved = $compound->save();
  1063. if($saved){
  1064. $gDate = $compound->created_at->format('F Y');
  1065. $historyData = [
  1066. 'tarikh_kumpulan' => $gDate,
  1067. ];
  1068. $subHistory = [
  1069. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1070. 'tajuk' => "Status notis ".$compound->kpd. " telah dikemaskini",
  1071. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1072. ];
  1073. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1074. if(!empty($groupByDate)){
  1075. $groupByDate->subhistory()->create($subHistory);
  1076. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1077. }else{
  1078. $history = History::create($historyData);
  1079. $history->subhistory()->create($subHistory);
  1080. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1081. }
  1082. if($request->status == "Berbayar"){
  1083. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1084. }else{
  1085. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1086. }
  1087. }else{
  1088. $response = [
  1089. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1090. ];
  1091. return response()->json($response, 200);
  1092. }
  1093. }else{
  1094. if($request->remark != ''){
  1095. $compound->catatan_dari_admin = $request->remark;
  1096. $compound->update_by = $request->current_id;
  1097. $compound->save();
  1098. $saved = $compound->save();
  1099. if($saved){
  1100. $gDate = $compound->created_at->format('F Y');
  1101. $historyData = [
  1102. 'tarikh_kumpulan' => $gDate,
  1103. ];
  1104. $subHistory = [
  1105. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1106. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1107. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1108. ];
  1109. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1110. if(!empty($groupByDate)){
  1111. $groupByDate->subhistory()->create($subHistory);
  1112. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1113. }else{
  1114. $history = History::create($historyData);
  1115. $history->subhistory()->create($subHistory);
  1116. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1117. }
  1118. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1119. }else{
  1120. $response = [
  1121. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1122. ];
  1123. return response()->json($response, 200);
  1124. }
  1125. }else{
  1126. $response = [
  1127. 'success' => false, 'message' => 'Tiada kemaskini!',
  1128. ];
  1129. return response()->json($response, 200);
  1130. }
  1131. }
  1132. }else{
  1133. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1134. $compound->status = $request->status;
  1135. $compound->catatan_dari_admin = $request->remark;
  1136. // $compound->amount_payment = $request->amount;
  1137. $compound->update_by = $request->current_id;
  1138. $saved = $compound->save();
  1139. if($saved){
  1140. $gDate = $compound->created_at->format('F Y');
  1141. $historyData = [
  1142. 'tarikh_kumpulan' => $gDate,
  1143. ];
  1144. $subHistory = [
  1145. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1146. 'tajuk' => "Status notis telah dikemaskini",
  1147. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1148. ];
  1149. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1150. if(!empty($groupByDate)){
  1151. $groupByDate->subhistory()->create($subHistory);
  1152. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1153. }else{
  1154. $history = History::create($historyData);
  1155. $history->subhistory()->create($subHistory);
  1156. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1157. }
  1158. if($request->status == "Berbayar"){
  1159. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1160. }else{
  1161. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1162. }
  1163. }else{
  1164. $response = [
  1165. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1166. ];
  1167. return response()->json($response, 200);
  1168. }
  1169. }else{
  1170. if($request->remark != ''){
  1171. $compound->catatan_dari_admin = $request->remark;
  1172. $compound->update_by = $request->current_id;
  1173. $compound->save();
  1174. $saved = $compound->save();
  1175. if($saved){
  1176. $gDate = $compound->created_at->format('F Y');
  1177. $historyData = [
  1178. 'tarikh_kumpulan' => $gDate,
  1179. ];
  1180. $subHistory = [
  1181. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1182. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1183. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1184. ];
  1185. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1186. if(!empty($groupByDate)){
  1187. $groupByDate->subhistory()->create($subHistory);
  1188. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1189. }else{
  1190. $history = History::create($historyData);
  1191. $history->subhistory()->create($subHistory);
  1192. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1193. }
  1194. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1195. }else{
  1196. $response = [
  1197. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1198. ];
  1199. return response()->json($response, 200);
  1200. }
  1201. }else{
  1202. $response = [
  1203. 'success' => false, 'message' => 'Tiada kemaskini!',
  1204. ];
  1205. return response()->json($response, 200);
  1206. }
  1207. }
  1208. }
  1209. }else{
  1210. $response = [
  1211. 'success' => false,
  1212. 'message' => 'Notis ini tidak dijumpai / staff tidak ditemui',
  1213. ];
  1214. return response()->json($response, 200);
  1215. }
  1216. }
  1217. public function updateStatusPaymentViaDashboard(Request $request)
  1218. {
  1219. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1220. $staff = StaffDetail::find($request->current_id);
  1221. if(!empty($compound) && !empty($staff)){
  1222. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1223. if($compound->status != $request->status){
  1224. $compound->status = $request->status;
  1225. $compound->catatan_dari_admin = $request->remark;
  1226. $compound->amount_payment = $request->amount;
  1227. $compound->update_by = $request->current_id;
  1228. $saved = $compound->save();
  1229. if($saved){
  1230. $gDate = $compound->created_at->format('F Y');
  1231. $historyData = [
  1232. 'tarikh_kumpulan' => $gDate,
  1233. ];
  1234. $subHistory = [
  1235. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1236. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1237. '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>",
  1238. ];
  1239. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1240. if(!empty($groupByDate)){
  1241. $groupByDate->subhistory()->create($subHistory);
  1242. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1243. }else{
  1244. $history = History::create($historyData);
  1245. $history->subhistory()->create($subHistory);
  1246. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1247. }
  1248. if($request->status == "Berbayar"){
  1249. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1250. }else{
  1251. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1252. }
  1253. }else{
  1254. $response = [
  1255. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1256. ];
  1257. return response()->json($response, 200);
  1258. }
  1259. }else{
  1260. if($request->remark != ''){
  1261. $compound->catatan_dari_admin = $request->remark;
  1262. $compound->update_by = $request->current_id;
  1263. $compound->save();
  1264. $saved = $compound->save();
  1265. if($saved){
  1266. $gDate = $compound->created_at->format('F Y');
  1267. $historyData = [
  1268. 'tarikh_kumpulan' => $gDate,
  1269. ];
  1270. $subHistory = [
  1271. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1272. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1273. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1274. ];
  1275. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1276. if(!empty($groupByDate)){
  1277. $groupByDate->subhistory()->create($subHistory);
  1278. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1279. }else{
  1280. $history = History::create($historyData);
  1281. $history->subhistory()->create($subHistory);
  1282. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1283. }
  1284. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1285. }else{
  1286. $response = [
  1287. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1288. ];
  1289. return response()->json($response, 200);
  1290. }
  1291. }else{
  1292. $response = [
  1293. 'success' => false, 'message' => 'Tiada kemaskini!',
  1294. ];
  1295. return response()->json($response, 200);
  1296. }
  1297. }
  1298. }else{
  1299. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1300. $compound->status = $request->status;
  1301. $compound->catatan_dari_admin = $request->remark;
  1302. $compound->amount_payment = $request->amount;
  1303. $compound->update_by = $request->current_id;
  1304. $saved = $compound->save();
  1305. if($saved){
  1306. $gDate = $compound->created_at->format('F Y');
  1307. $historyData = [
  1308. 'tarikh_kumpulan' => $gDate,
  1309. ];
  1310. $subHistory = [
  1311. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1312. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1313. '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>",
  1314. ];
  1315. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1316. if(!empty($groupByDate)){
  1317. $groupByDate->subhistory()->create($subHistory);
  1318. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1319. }else{
  1320. $history = History::create($historyData);
  1321. $history->subhistory()->create($subHistory);
  1322. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1323. }
  1324. if($request->status == "Berbayar"){
  1325. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1326. }else{
  1327. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1328. }
  1329. }else{
  1330. $response = [
  1331. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1332. ];
  1333. return response()->json($response, 200);
  1334. }
  1335. }else{
  1336. if($request->remark != ''){
  1337. $compound->catatan_dari_admin = $request->remark;
  1338. $compound->update_by = $request->current_id;
  1339. $compound->save();
  1340. $saved = $compound->save();
  1341. if($saved){
  1342. $gDate = $compound->created_at->format('F Y');
  1343. $historyData = [
  1344. 'tarikh_kumpulan' => $gDate,
  1345. ];
  1346. $subHistory = [
  1347. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1348. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1349. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1350. ];
  1351. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1352. if(!empty($groupByDate)){
  1353. $groupByDate->subhistory()->create($subHistory);
  1354. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1355. }else{
  1356. $history = History::create($historyData);
  1357. $history->subhistory()->create($subHistory);
  1358. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1359. }
  1360. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1361. }else{
  1362. $response = [
  1363. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1364. ];
  1365. return response()->json($response, 200);
  1366. }
  1367. }else{
  1368. $response = [
  1369. 'success' => false, 'message' => 'Tiada kemaskini!',
  1370. ];
  1371. return response()->json($response, 200);
  1372. }
  1373. }
  1374. }
  1375. }else{
  1376. $response = [
  1377. 'success' => false,
  1378. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  1379. ];
  1380. return response()->json($response, 200);
  1381. }
  1382. }
  1383. /**
  1384. * Remove the specified resource from storage.
  1385. *
  1386. * @param int $id
  1387. * @return \Illuminate\Http\Response
  1388. */
  1389. public function destroy($id)
  1390. {
  1391. //
  1392. }
  1393. }