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

CompoundResourceController.php 74KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643
  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 with tag
  353. $kpd = $tag . $kpd;
  354. return $kpd;
  355. }
  356. /**
  357. * Store a created compound from notice.
  358. *
  359. * @param \Illuminate\Http\Request $request
  360. * @return \Illuminate\Http\Response
  361. */
  362. public function store(Request $request)
  363. {
  364. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  365. if(empty($staff)){
  366. return $this->sendError('Invalid', 'Staff not existed');
  367. }else {
  368. $saved ='';
  369. $kpd = '';
  370. $no_siri = '';
  371. $data = array();
  372. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  373. if($request->jenis == 'Parkir')
  374. {
  375. if(!empty($faulty)){
  376. $countKPD = $this->compound->withTrashed()->count();
  377. do {
  378. $countKPD = $countKPD + 1;
  379. } while (!empty(Compound::where("kpd", "=", 'KP'.$countKPD)->first()));
  380. $kpd = 'KP'.$countKPD;
  381. $no_siri = date('yn').'-'.$countKPD;
  382. $fileData = [
  383. 'no_siri' => $no_siri,
  384. ];
  385. //only for compound parkir
  386. $compoundData = [
  387. 'jenis' => 'Parkir',
  388. 'kpd' => 'KPD'.$kpd,
  389. 'nama' => '-',
  390. 'identity' => '-',
  391. 'alamat' => '-',
  392. "no_plate" => strtolower($request->no_plate),
  393. "no_cukai_jalan" => $request->noCukaijalan,
  394. "jenis_kenderaan" => $request->jenisKenderaan,
  395. "model_kenderaan" => $request->modelKenderaan,
  396. "warna_kenderaan" => $request->warnakenderaan,
  397. "nama_kawasan" => $request->namaKawasan,
  398. "nama_taman" => $request->namaTaman,
  399. "nama_jalan" => $request->namaJalan,
  400. "no_parking" => $request->noParking,
  401. "catatan" => $request->catatan,
  402. "lokasi_kejadian" => '-',
  403. 'latlong' => $request->Latlong,
  404. 'jbkod' => $request->jabatan,
  405. 'akta' => $faulty->deed_law_id,
  406. 'seksyen_kesalahan' => $faulty->_id,
  407. 'jumlah_asal_kompaun' => $faulty->amount,
  408. 'jumlah_kemaskini_kompaun' => '-',
  409. 'dikeluarkan' => $staff->_id,
  410. "status" => 'Belum Bayar',
  411. "amount_payment" => '-',
  412. "receipt" => '-',
  413. "modul" => '03',
  414. "penguatkuasa" => '-',
  415. "cpn_created" => Carbon::now()->toDateTimeString(),
  416. ];
  417. $file = ConfidentialFile::create($fileData);
  418. $saved = $file->compound()->create($compoundData);
  419. }
  420. }elseif(($request->jenis == 'Pelbagai_KT') || ($request->jenis == 'Pelbagai_JPB') || ($request->jenis == 'Pelbagai_PA') || ($request->jenis == 'Pelbagai_LESEN')){
  421. $kpd = $request->kpd;
  422. $compound = Compound::where('jenis', $request->jenis)->where('kpd', $kpd)->first();
  423. info($compound);
  424. if (!empty($compound)) {
  425. $saved = '';
  426. if($compound->modul != '03')
  427. {
  428. if($request->jenis == 'Pelbagai_KT'){
  429. $compound->jenis = $request->jenis;
  430. $compound->nama = $request->namaP;
  431. $compound->identity = $request->noIc;
  432. $compound->nama_syarikat = $request->namaS;
  433. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  434. $compound->alamat = $request->alamat;
  435. $compound->no_plate = $request->no_plate;
  436. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  437. // $compound->nama_kawasan = $request->namaKawasan;
  438. // $compound->nama_taman = $request->namaTaman;
  439. // $compound->nama_jalan = $request->namaJalan;
  440. $compound->catatan = $request->catatan;
  441. $compound->latlong = $request->Latlong;
  442. // $compound->akta = $faulty->deed_law_id;
  443. // $compound->seksyen_kesalahan = $faulty->_id;
  444. // $compound->jumlah_asal_kompaun = $faulty->amount;
  445. $compound->dikeluarkan_ = $staff->_id;
  446. $compound->status = 'Belum Bayar';
  447. $compound->modul = '03';
  448. $compound->no_telefon = $request->tel;
  449. $compound->no_akaun_lesen = $request->lesen;
  450. $compound->cpn_created = Carbon::now()->toDateTimeString();
  451. }elseif($request->jenis == 'Pelbagai_JPB'){
  452. $compound->jenis = $request->jenis;
  453. $compound->nama = $request->namaP;
  454. $compound->identity = $request->noIc;
  455. $compound->nama_syarikat = $request->namaS;
  456. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  457. $compound->alamat = $request->alamat;
  458. $compound->no_plate = $request->no_plate;
  459. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  460. // $compound->nama_kawasan => $request->namaKawasan;
  461. // $compound->nama_taman => $request->namaTaman;
  462. // $compound->nama_jalan => $request->namaJalan;
  463. $compound->catatan = $request->catatan;
  464. $compound->latlong = $request->Latlong;
  465. // $compound->akta => $faulty->deed_law_id;
  466. // $compound->seksyen_kesalahan => $faulty->_id;
  467. // $compound->jumlah_asal_kompaun => $faulty->amount;
  468. $compound->dikeluarkan_ = $staff->_id;
  469. $compound->status = 'Belum Bayar';
  470. $compound->modul = '03';
  471. $compound->no_telefon = $request->tel;
  472. $compound->no_akaun_lesen = $request->lesen;
  473. $compound->cpn_created = Carbon::now()->toDateTimeString();
  474. }elseif($request->jenis == 'Pelbagai_PA'){
  475. $compound->jenis = $request->jenis;
  476. $compound->nama = $request->namaP;
  477. $compound->identity = $request->noIc;
  478. $compound->nama_syarikat = $request->namaS;
  479. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  480. $compound->alamat = $request->alamat;
  481. $compound->no_plate = $request->no_plate;
  482. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  483. // $compound->nama_kawasan = $request->namaKawasan;
  484. // $compound->nama_taman = $request->namaTaman;
  485. // $compound->nama_jalan = $request->namaJalan;
  486. $compound->catatan = $request->catatan;
  487. $compound->latlong = $request->Latlong;
  488. // $compound->akta = $faulty->deed_law_id;
  489. // $compound->seksyen_kesalahan = $faulty->_id;
  490. // $compound->jumlah_asal_kompaun = $faulty->amount;
  491. $compound->dikeluarkan_ = $staff->_id;
  492. $compound->status = 'Belum Bayar';
  493. $compound->modul = '03';
  494. $compound->no_telefon = $request->tel;
  495. $compound->no_akaun_lesen = $request->lesen;
  496. $compound->bil_haiwan = $request->lesen;
  497. $compound->cpn_created = Carbon::now()->toDateTimeString();
  498. }elseif($request->jenis == 'Pelbagai_LESEN'){
  499. $compound->jenis = $request->jenis;
  500. $compound->nama = $request->namaP;
  501. $compound->identity = $request->noIc;
  502. $compound->nama_syarikat = $request->namaS;
  503. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  504. $compound->alamat = $request->alamat;
  505. $compound->no_plate = $request->no_plate;
  506. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  507. // $compound->nama_kawasan = $request->namaKawasan;
  508. // $compound->nama_taman = $request->namaTaman;
  509. // $compound->nama_jalan = $request->namaJalan;
  510. $compound->catatan = $request->catatan;
  511. $compound->latlong = $request->Latlong;
  512. // $compound->akta = $faulty->deed_law_id;
  513. // $compound->seksyen_kesalahan = $faulty->_id;
  514. // $compound->jumlah_asal_kompaun = $faulty->amount;
  515. $compound->dikeluarkan_ = $staff->_id;
  516. $compound->status = 'Belum Bayar';
  517. $compound->modul = '03';
  518. $compound->no_telefon = $request->tel;
  519. $compound->no_akaun_lesen = $request->lesen;
  520. $compound->cpn_created = Carbon::now()->toDateTimeString();
  521. }
  522. $saved = $compound->save();
  523. }
  524. else
  525. {
  526. return $this->sendResponse('', 'Kompaun ini telah dikeluarkan!');
  527. }
  528. if($saved){
  529. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  530. // if(!empty($compound)){
  531. dispatch(new UpdateCompoundPrice($kpd));
  532. // $tawaran = '';
  533. // if($compound->jumlah_kemaskini_kompaun != ''){
  534. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  535. // }else{
  536. // $tawaran = $compound->jumlah_asal_kompaun;
  537. // }
  538. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  539. array_push($data, array('kpd' => $kpd));
  540. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  541. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  542. // }
  543. }
  544. }
  545. else{
  546. return $this->sendResponse('', 'Kompaun ini tidak dijumpai!');
  547. }
  548. }
  549. }
  550. }
  551. /**
  552. *
  553. * Store a newly created notice
  554. *
  555. **/
  556. public function storeNewNotice(Request $request)
  557. {
  558. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  559. if(empty($staff)){
  560. return $this->sendError('Invalid', 'Staff not existed');
  561. }else {
  562. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  563. if(!empty($faulty)){
  564. $data = array();
  565. $kpd = '';
  566. $no_siri ='';
  567. // $countKPD = $this->compound->withTrashed()->count(); //for parking numbering
  568. // do {
  569. // $kpd = $kpd + 1;
  570. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  571. // $kpd = 'KP'.$countKPD;
  572. // $no_siri = date('yn').'-'.$countKPD;
  573. // $fileData = [
  574. // 'no_siri' => $no_siri,
  575. // ];
  576. if($request->jenis == 'Parkir'){
  577. //for compound numbering
  578. $countKPD = $this->compound->withTrashed()->count();
  579. $no_siri = date('yn').'-'.$countKPD.'-0';
  580. $compoundData = [
  581. 'jenis' => 'Parkir',
  582. 'kpd' => 'KPD'.$countKPD,
  583. 'nama' => '-',
  584. 'identity' => '-',
  585. 'alamat' => '-',
  586. "no_plate" => strtolower($request->no_plate),
  587. "no_cukai_jalan" => $request->noCukaijalan,
  588. "jenis_kenderaan" => $request->jenisKenderaan,
  589. "model_kenderaan" => $request->modelKenderaan,
  590. "warna_kenderaan" => $request->warnakenderaan,
  591. "nama_kawasan" => $request->namaKawasan,
  592. "nama_taman" => $request->namaTaman,
  593. "nama_jalan" => $request->namaJalan,
  594. "no_parking" => $request->noParking,
  595. "catatan" => $request->catatan,
  596. "lokasi_kejadian" => '-',
  597. 'latlong' => $request->Latlong,
  598. 'jbkod' => $request->jabatan,
  599. 'akta' => $faulty->deed_law_id,
  600. 'seksyen_kesalahan' => $faulty->_id,
  601. 'jumlah_asal_kompaun' => $faulty->amount,
  602. 'jumlah_kemaskini_kompaun' => '-',
  603. 'dikeluarkan' => $staff->_id,
  604. "status" => 'Belum Bayar',
  605. "amount_payment" => '-',
  606. "receipt" => '-',
  607. "modul" => $request->modul,
  608. "penguatkuasa" => '-',
  609. "notis_created" => Carbon::now()->toDateTimeString(),
  610. ];
  611. }elseif($request->jenis == 'Pelbagai_KT'){
  612. $kpd = $this->generateCompoundNumber($request->jenis, 'KT');
  613. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  614. $compoundData = [
  615. 'jenis' => $request->jenis,
  616. 'kpd' => $kpd,
  617. 'non' => 'NKG'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT),
  618. 'nama' => $request->namaP,
  619. 'identity' => $request->noIc,
  620. 'nama_syarikat' => $request->namaS,
  621. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  622. 'alamat' => $request->alamat,
  623. "no_plate" => $request->no_plate,
  624. "no_cukai_jalan" => $request->no_cukai_jalan,
  625. "nama_kawasan" => $request->namaKawasan,
  626. "nama_taman" => $request->namaTaman,
  627. "nama_jalan" => $request->namaJalan,
  628. "catatan" => $request->catatan,
  629. "lokasi_kejadian" => '-',
  630. 'latlong' => $request->Latlong,
  631. 'jbkod' => $request->jabatan,
  632. 'akta' => $faulty->deed_law_id,
  633. 'seksyen_kesalahan' => $faulty->_id,
  634. 'jumlah_asal_kompaun' => $faulty->amount,
  635. 'jumlah_kemaskini_kompaun' => '-',
  636. 'dikeluarkan' => $staff->_id,
  637. "status" => 'Belum Bayar',
  638. "amount_payment" => '-',
  639. "receipt" => '-',
  640. "modul" => $request->modul,
  641. "penguatkuasa" => '-',
  642. "no_telefon" => $request->tel,
  643. "no_akaun_lesen" => $request->lesen,
  644. "maklumat_tambahan" => '-',
  645. "tindakan" => $request->tindakan,
  646. "tempoh" => $request->tempoh,
  647. "notis_created" => Carbon::now()->toDateTimeString(),
  648. ];
  649. }elseif($request->jenis == 'Pelbagai_JPB'){
  650. $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  651. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  652. $compoundData = [
  653. 'jenis' => $request->jenis,
  654. 'kpd' => $kpd,
  655. 'non' => 'NMH'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT),
  656. 'nama' => $request->namaP,
  657. 'identity' => $request->noIc,
  658. 'nama_syarikat' => $request->namaS,
  659. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  660. 'alamat' => $request->alamat,
  661. "no_plate" => $request->no_plate,
  662. "no_cukai_jalan" => $request->no_cukai_jalan,
  663. "nama_kawasan" => $request->namaKawasan,
  664. "nama_taman" => $request->namaTaman,
  665. "nama_jalan" => $request->namaJalan,
  666. "catatan" => $request->catatan,
  667. "lokasi_kejadian" => '-',
  668. 'latlong' => $request->Latlong,
  669. 'jbkod' => $request->jabatan,
  670. 'akta' => $faulty->deed_law_id,
  671. 'seksyen_kesalahan' => $faulty->_id,
  672. 'jumlah_asal_kompaun' => $faulty->amount,
  673. 'jumlah_kemaskini_kompaun' => '-',
  674. 'dikeluarkan' => $staff->_id,
  675. "status" => 'Belum Bayar',
  676. "amount_payment" => '-',
  677. "receipt" => '-',
  678. "modul" => $request->modul,
  679. "penguatkuasa" => '-',
  680. "no_telefon" => $request->tel,
  681. "no_akaun_lesen" => $request->lesen,
  682. "maklumat_tambahan" => '-',
  683. "tindakan" => $request->tindakan,
  684. "tempoh" => $request->tempoh,
  685. "notis_created" => Carbon::now()->toDateTimeString(),
  686. ];
  687. }
  688. elseif($request->jenis == 'Pelbagai_LESEN'){
  689. //HN bcs other N stands for notice. compound number no need front N
  690. $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  691. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-3';
  692. $compoundData = [
  693. 'jenis' => $request->jenis,
  694. 'kpd' => $kpd,
  695. 'non' => 'NHN'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT),
  696. 'nama' => $request->namaP,
  697. 'identity' => $request->noIc,
  698. 'nama_syarikat' => $request->namaS,
  699. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  700. 'alamat' => $request->alamat,
  701. "no_plate" => $request->no_plate,
  702. "no_cukai_jalan" => $request->no_cukai_jalan,
  703. "nama_kawasan" => $request->namaKawasan,
  704. "nama_taman" => $request->namaTaman,
  705. "nama_jalan" => $request->namaJalan,
  706. "catatan" => $request->catatan,
  707. "lokasi_kejadian" => '-',
  708. 'latlong' => $request->Latlong,
  709. 'jbkod' => $request->jabatan,
  710. 'akta' => $faulty->deed_law_id,
  711. 'seksyen_kesalahan' => $faulty->_id,
  712. 'jumlah_asal_kompaun' => $faulty->amount,
  713. 'jumlah_kemaskini_kompaun' => '-',
  714. 'dikeluarkan' => $staff->_id,
  715. "status" => 'Belum Bayar',
  716. "amount_payment" => '-',
  717. "receipt" => '-',
  718. "modul" => $request->modul,
  719. "penguatkuasa" => '-',
  720. "no_telefon" => $request->tel,
  721. "no_akaun_lesen" => $request->lesen,
  722. "maklumat_tambahan" => '-',
  723. "notis_created" => Carbon::now()->toDateTimeString(),
  724. ];
  725. }
  726. elseif($request->jenis == 'Pelbagai_PA'){
  727. $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  728. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-4';
  729. $compoundData = [
  730. 'jenis' => $request->jenis,
  731. 'kpd' => $kpd,
  732. 'non' => 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT),
  733. 'nama' => $request->namaP,
  734. 'identity' => $request->noIc,
  735. 'nama_syarikat' => $request->namaS,
  736. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  737. 'alamat' => $request->alamat,
  738. "no_plate" => $request->no_plate,
  739. "no_cukai_jalan" => $request->no_cukai_jalan,
  740. "nama_kawasan" => $request->namaKawasan,
  741. "nama_taman" => $request->namaTaman,
  742. "nama_jalan" => $request->namaJalan,
  743. "catatan" => $request->catatan,
  744. "lokasi_kejadian" => '-',
  745. 'latlong' => $request->Latlong,
  746. 'jbkod' => $request->jabatan,
  747. 'akta' => $faulty->deed_law_id,
  748. 'seksyen_kesalahan' => $faulty->_id,
  749. 'jumlah_asal_kompaun' => $faulty->amount,
  750. 'jumlah_kemaskini_kompaun' => '-',
  751. 'dikeluarkan' => $staff->_id,
  752. "status" => 'Belum Bayar',
  753. "amount_payment" => '-',
  754. "receipt" => '-',
  755. "modul" => $request->modul,
  756. "penguatkuasa" => '-',
  757. "no_telefon" => $request->tel,
  758. "no_akaun_lesen" => $request->lesen,
  759. "maklumat_tambahan" => '-',
  760. "bil_haiwan" => $request->bil_haiwan,
  761. "notis_created" => Carbon::now()->toDateTimeString(),
  762. ];
  763. }
  764. $fileData = [
  765. 'no_siri' => $no_siri,
  766. ];
  767. $file = ConfidentialFile::create($fileData);
  768. $saved = $file->compound()->create($compoundData);
  769. if($saved){
  770. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  771. // if(!empty($compound)){
  772. dispatch(new UpdateCompoundPrice($kpd));
  773. // $tawaran = '';
  774. // if($compound->jumlah_kemaskini_kompaun != ''){
  775. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  776. // }else{
  777. // $tawaran = $compound->jumlah_asal_kompaun;
  778. // }
  779. $this->dispatch(new StoreNotice($request->all(), $kpd, $staff->_id, $no_siri));
  780. array_push($data, array('kpd' => $kpd));
  781. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  782. // }
  783. }
  784. }
  785. }
  786. }
  787. /**
  788. * Store a newly created compound (parkir, KT, JPB).
  789. *
  790. * @param \Illuminate\Http\Request $request
  791. * @return \Illuminate\Http\Response
  792. */
  793. public function storeNewCompound(Request $request)
  794. {
  795. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  796. if(empty($staff)){
  797. return $this->sendError('Invalid', 'Staff not existed');
  798. }else {
  799. $data = array();
  800. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  801. if(!empty($faulty)){
  802. $kpd = '';
  803. $no_siri ='';
  804. // $countKPD = $this->compound->withTrashed()->count();
  805. // do {
  806. // $countKPD = $countKPD + 1;
  807. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  808. // $kpd = $countKPD;
  809. // $no_siri = date('yn').'-'.$countKPD;
  810. // $fileData = [
  811. // 'no_siri' => $no_siri,
  812. // ];
  813. if($request->jenis == 'Parkir')
  814. {
  815. //for compound numbering
  816. $countKPD = $this->compound->withTrashed()->count();
  817. $no_siri = date('yn').'-'.$countKPD.'-0';
  818. //only for compound parkir
  819. $compoundData = [
  820. 'jenis' => 'Parkir',
  821. 'kpd' => 'KPD'.$countKPD,
  822. 'nama' => '-',
  823. 'identity' => '-',
  824. 'alamat' => '-',
  825. "no_plate" => strtolower($request->no_plate),
  826. "no_cukai_jalan" => $request->noCukaijalan,
  827. "jenis_kenderaan" => $request->jenisKenderaan,
  828. "model_kenderaan" => $request->modelKenderaan,
  829. "warna_kenderaan" => $request->warnakenderaan,
  830. "nama_kawasan" => $request->namaKawasan,
  831. "nama_taman" => $request->namaTaman,
  832. "nama_jalan" => $request->namaJalan,
  833. "no_parking" => $request->noParking,
  834. "catatan" => $request->catatan,
  835. "lokasi_kejadian" => '-',
  836. 'latlong' => $request->Latlong,
  837. 'jbkod' => $request->jabatan,
  838. 'akta' => $faulty->deed_law_id,
  839. 'seksyen_kesalahan' => $faulty->_id,
  840. 'jumlah_asal_kompaun' => $faulty->amount,
  841. 'jumlah_kemaskini_kompaun' => '-',
  842. 'dikeluarkan' => $staff->_id,
  843. "status" => 'Belum Bayar',
  844. "amount_payment" => '-',
  845. "receipt" => '-',
  846. "modul" => '03',
  847. "penguatkuasa" => '-',
  848. "cpn_created" => Carbon::now()->toDateTimeString(),
  849. ];
  850. }
  851. if ($request->jenis == 'Pelbagai_KT') {
  852. $kpd = $this->generateCompoundNumber($request->jenis, 'KT');
  853. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  854. $compoundData = [
  855. 'jenis' => $request->jenis,
  856. 'kpd' => $kpd,
  857. 'nama' => $request->namaP,
  858. 'identity' => $request->noIc,
  859. 'nama_syarikat' => $request->namaS,
  860. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  861. 'alamat' => $request->alamat,
  862. "no_plate" => $request->no_plate,
  863. "no_cukai_jalan" => $request->no_cukai_jalan,
  864. "nama_kawasan" => $request->namaKawasan,
  865. "nama_taman" => $request->namaTaman,
  866. "nama_jalan" => $request->namaJalan,
  867. "catatan" => $request->catatan,
  868. "lokasi_kejadian" => '-',
  869. 'latlong' => $request->Latlong,
  870. 'jbkod' => $request->jabatan,
  871. 'akta' => $faulty->deed_law_id,
  872. 'seksyen_kesalahan' => $faulty->_id,
  873. 'jumlah_asal_kompaun' => $faulty->amount,
  874. 'jumlah_kemaskini_kompaun' => '-',
  875. 'dikeluarkan' => $staff->_id,
  876. "status" => 'Belum Bayar',
  877. "amount_payment" => '-',
  878. "receipt" => '-',
  879. "modul" => $request->modul,
  880. "penguatkuasa" => '-',
  881. "no_telefon" => $request->tel,
  882. "no_akaun_lesen" => $request->lesen,
  883. "maklumat_tambahan" => '-',
  884. "tindakan" => '-',
  885. "tempoh" => '-',
  886. "cpn_created" => Carbon::now()->toDateTimeString(),
  887. ];
  888. }
  889. elseif ($request->jenis == 'Pelbagai_JPB') {
  890. $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  891. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  892. $compoundData = [
  893. 'jenis' => $request->jenis,
  894. 'kpd' => $kpd,
  895. 'nama' => $request->namaP,
  896. 'identity' => $request->noIc,
  897. 'nama_syarikat' => $request->namaS,
  898. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  899. 'alamat' => $request->alamat,
  900. "no_plate" => $request->no_plate,
  901. "no_cukai_jalan" => $request->no_cukai_jalan,
  902. "nama_kawasan" => $request->namaKawasan,
  903. "nama_taman" => $request->namaTaman,
  904. "nama_jalan" => $request->namaJalan,
  905. "catatan" => $request->catatan,
  906. "lokasi_kejadian" => '-',
  907. 'latlong' => $request->Latlong,
  908. 'jbkod' => $request->jabatan,
  909. 'akta' => $faulty->deed_law_id,
  910. 'seksyen_kesalahan' => $faulty->_id,
  911. 'jumlah_asal_kompaun' => $faulty->amount,
  912. 'jumlah_kemaskini_kompaun' => '-',
  913. 'dikeluarkan' => $staff->_id,
  914. "status" => 'Belum Bayar',
  915. "amount_payment" => '-',
  916. "receipt" => '-',
  917. "modul" => $request->modul,
  918. "penguatkuasa" => '-',
  919. "no_telefon" => $request->tel,
  920. "no_akaun_lesen" => $request->lesen,
  921. "maklumat_tambahan" => '-',
  922. "tindakan" => '-',
  923. "tempoh" => '-',
  924. "cpn_created" => Carbon::now()->toDateTimeString(),
  925. ];
  926. }
  927. elseif ($request->jenis == 'Pelbagai_LESEN') {
  928. //HN bcs other N stands for notice. compound number no need front N
  929. $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  930. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-3';
  931. $compoundData = [
  932. 'jenis' => $request->jenis,
  933. 'kpd' => $kpd,
  934. 'nama' => $request->namaP,
  935. 'identity' => $request->noIc,
  936. 'nama_syarikat' => $request->namaS,
  937. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  938. 'alamat' => $request->alamat,
  939. "no_plate" => $request->no_plate,
  940. "no_cukai_jalan" => $request->no_cukai_jalan,
  941. "nama_kawasan" => $request->namaKawasan,
  942. "nama_taman" => $request->namaTaman,
  943. "nama_jalan" => $request->namaJalan,
  944. "catatan" => $request->catatan,
  945. "lokasi_kejadian" => '-',
  946. 'latlong' => $request->Latlong,
  947. 'jbkod' => $request->jabatan,
  948. 'akta' => $faulty->deed_law_id,
  949. 'seksyen_kesalahan' => $faulty->_id,
  950. 'jumlah_asal_kompaun' => $faulty->amount,
  951. 'jumlah_kemaskini_kompaun' => '-',
  952. 'dikeluarkan' => $staff->_id,
  953. "status" => 'Belum Bayar',
  954. "amount_payment" => '-',
  955. "receipt" => '-',
  956. "modul" => $request->modul,
  957. "penguatkuasa" => '-',
  958. "no_telefon" => $request->tel,
  959. "no_akaun_lesen" => $request->lesen,
  960. "maklumat_tambahan" => '-',
  961. "cpn_created" => Carbon::now()->toDateTimeString(),
  962. ];
  963. }
  964. else if($request->jenis == 'Pelbagai_PA'){
  965. $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  966. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-4';
  967. $compoundData = [
  968. 'jenis' => $request->jenis,
  969. 'kpd' => $kpd,
  970. 'nama' => $request->namaP,
  971. 'identity' => $request->noIc,
  972. 'nama_syarikat' => $request->namaS,
  973. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  974. 'alamat' => $request->alamat,
  975. "no_plate" => $request->no_plate,
  976. "no_cukai_jalan" => $request->no_cukai_jalan,
  977. "nama_kawasan" => $request->namaKawasan,
  978. "nama_taman" => $request->namaTaman,
  979. "nama_jalan" => $request->namaJalan,
  980. "catatan" => $request->catatan,
  981. "lokasi_kejadian" => '-',
  982. 'latlong' => $request->Latlong,
  983. 'jbkod' => $request->jabatan,
  984. 'akta' => $faulty->deed_law_id,
  985. 'seksyen_kesalahan' => $faulty->_id,
  986. 'jumlah_asal_kompaun' => $faulty->amount,
  987. 'jumlah_kemaskini_kompaun' => '-',
  988. 'dikeluarkan' => $staff->_id,
  989. "status" => 'Belum Bayar',
  990. "amount_payment" => '-',
  991. "receipt" => '-',
  992. "modul" => $request->modul,
  993. "penguatkuasa" => '-',
  994. "no_telefon" => $request->tel,
  995. "no_akaun_lesen" => $request->lesen,
  996. "maklumat_tambahan" => '-',
  997. "bil_haiwan" => $request->bil_haiwan,
  998. "cpn_created" => Carbon::now()->toDateTimeString(),
  999. ];
  1000. }
  1001. $fileData = [
  1002. 'no_siri' => $no_siri,
  1003. ];
  1004. $file = ConfidentialFile::create($fileData);
  1005. $saved = $file->compound()->create($compoundData);
  1006. if($saved){
  1007. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  1008. // if(!empty($compound)){
  1009. dispatch(new UpdateCompoundPrice($kpd));
  1010. // $tawaran = '';
  1011. // if($compound->jumlah_kemaskini_kompaun != ''){
  1012. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  1013. // }else{
  1014. // $tawaran = $compound->jumlah_asal_kompaun;
  1015. // }
  1016. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  1017. array_push($data, array('kpd' => $kpd));
  1018. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  1019. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  1020. }
  1021. }
  1022. return $this->sendResponse('Tidak Berjaya!', 'Kesalahan tidak dijumpai!');
  1023. }
  1024. }
  1025. /**
  1026. * Display the specified resource.
  1027. *
  1028. * @param int $id
  1029. * @return \Illuminate\Http\Response
  1030. */
  1031. public function show($id)
  1032. {
  1033. //
  1034. }
  1035. /**
  1036. * Show the form for editing the specified resource.
  1037. *
  1038. * @param int $id
  1039. * @return \Illuminate\Http\Response
  1040. */
  1041. public function edit($id)
  1042. {
  1043. //
  1044. }
  1045. /**
  1046. * Update the specified resource in storage.
  1047. *
  1048. * @param \Illuminate\Http\Request $request
  1049. * @param int $id
  1050. * @return \Illuminate\Http\Response
  1051. */
  1052. public function update(Request $request, $id)
  1053. {
  1054. //
  1055. }
  1056. public function updateStatusNoticeViaDashboard(Request $request)
  1057. {
  1058. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1059. $staff = StaffDetail::find($request->current_id);
  1060. if(!empty($compound) && !empty($staff)){
  1061. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1062. if($compound->status != $request->status){
  1063. $compound->status = $request->status;
  1064. $compound->catatan_dari_admin = $request->remark;
  1065. $compound->update_by = $request->current_id;
  1066. $saved = $compound->save();
  1067. if($saved){
  1068. $gDate = $compound->created_at->format('F Y');
  1069. $historyData = [
  1070. 'tarikh_kumpulan' => $gDate,
  1071. ];
  1072. $subHistory = [
  1073. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1074. 'tajuk' => "Status notis ".$compound->kpd. " telah dikemaskini",
  1075. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1076. ];
  1077. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1078. if(!empty($groupByDate)){
  1079. $groupByDate->subhistory()->create($subHistory);
  1080. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1081. }else{
  1082. $history = History::create($historyData);
  1083. $history->subhistory()->create($subHistory);
  1084. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1085. }
  1086. if($request->status == "Berbayar"){
  1087. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1088. }else{
  1089. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1090. }
  1091. }else{
  1092. $response = [
  1093. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1094. ];
  1095. return response()->json($response, 200);
  1096. }
  1097. }else{
  1098. if($request->remark != ''){
  1099. $compound->catatan_dari_admin = $request->remark;
  1100. $compound->update_by = $request->current_id;
  1101. $compound->save();
  1102. $saved = $compound->save();
  1103. if($saved){
  1104. $gDate = $compound->created_at->format('F Y');
  1105. $historyData = [
  1106. 'tarikh_kumpulan' => $gDate,
  1107. ];
  1108. $subHistory = [
  1109. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1110. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1111. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1112. ];
  1113. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1114. if(!empty($groupByDate)){
  1115. $groupByDate->subhistory()->create($subHistory);
  1116. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1117. }else{
  1118. $history = History::create($historyData);
  1119. $history->subhistory()->create($subHistory);
  1120. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1121. }
  1122. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1123. }else{
  1124. $response = [
  1125. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1126. ];
  1127. return response()->json($response, 200);
  1128. }
  1129. }else{
  1130. $response = [
  1131. 'success' => false, 'message' => 'Tiada kemaskini!',
  1132. ];
  1133. return response()->json($response, 200);
  1134. }
  1135. }
  1136. }else{
  1137. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1138. $compound->status = $request->status;
  1139. $compound->catatan_dari_admin = $request->remark;
  1140. // $compound->amount_payment = $request->amount;
  1141. $compound->update_by = $request->current_id;
  1142. $saved = $compound->save();
  1143. if($saved){
  1144. $gDate = $compound->created_at->format('F Y');
  1145. $historyData = [
  1146. 'tarikh_kumpulan' => $gDate,
  1147. ];
  1148. $subHistory = [
  1149. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1150. 'tajuk' => "Status notis telah dikemaskini",
  1151. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1152. ];
  1153. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1154. if(!empty($groupByDate)){
  1155. $groupByDate->subhistory()->create($subHistory);
  1156. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1157. }else{
  1158. $history = History::create($historyData);
  1159. $history->subhistory()->create($subHistory);
  1160. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1161. }
  1162. if($request->status == "Berbayar"){
  1163. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1164. }else{
  1165. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1166. }
  1167. }else{
  1168. $response = [
  1169. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1170. ];
  1171. return response()->json($response, 200);
  1172. }
  1173. }else{
  1174. if($request->remark != ''){
  1175. $compound->catatan_dari_admin = $request->remark;
  1176. $compound->update_by = $request->current_id;
  1177. $compound->save();
  1178. $saved = $compound->save();
  1179. if($saved){
  1180. $gDate = $compound->created_at->format('F Y');
  1181. $historyData = [
  1182. 'tarikh_kumpulan' => $gDate,
  1183. ];
  1184. $subHistory = [
  1185. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1186. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1187. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1188. ];
  1189. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1190. if(!empty($groupByDate)){
  1191. $groupByDate->subhistory()->create($subHistory);
  1192. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1193. }else{
  1194. $history = History::create($historyData);
  1195. $history->subhistory()->create($subHistory);
  1196. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1197. }
  1198. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1199. }else{
  1200. $response = [
  1201. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1202. ];
  1203. return response()->json($response, 200);
  1204. }
  1205. }else{
  1206. $response = [
  1207. 'success' => false, 'message' => 'Tiada kemaskini!',
  1208. ];
  1209. return response()->json($response, 200);
  1210. }
  1211. }
  1212. }
  1213. }else{
  1214. $response = [
  1215. 'success' => false,
  1216. 'message' => 'Notis ini tidak dijumpai / staff tidak ditemui',
  1217. ];
  1218. return response()->json($response, 200);
  1219. }
  1220. }
  1221. public function updateStatusPaymentViaDashboard(Request $request)
  1222. {
  1223. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1224. $staff = StaffDetail::find($request->current_id);
  1225. if(!empty($compound) && !empty($staff)){
  1226. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1227. if($compound->status != $request->status){
  1228. $compound->status = $request->status;
  1229. $compound->catatan_dari_admin = $request->remark;
  1230. $compound->amount_payment = $request->amount;
  1231. $compound->update_by = $request->current_id;
  1232. $saved = $compound->save();
  1233. if($saved){
  1234. $gDate = $compound->created_at->format('F Y');
  1235. $historyData = [
  1236. 'tarikh_kumpulan' => $gDate,
  1237. ];
  1238. $subHistory = [
  1239. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1240. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1241. '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>",
  1242. ];
  1243. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1244. if(!empty($groupByDate)){
  1245. $groupByDate->subhistory()->create($subHistory);
  1246. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1247. }else{
  1248. $history = History::create($historyData);
  1249. $history->subhistory()->create($subHistory);
  1250. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1251. }
  1252. if($request->status == "Berbayar"){
  1253. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1254. }else{
  1255. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1256. }
  1257. }else{
  1258. $response = [
  1259. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1260. ];
  1261. return response()->json($response, 200);
  1262. }
  1263. }else{
  1264. if($request->remark != ''){
  1265. $compound->catatan_dari_admin = $request->remark;
  1266. $compound->update_by = $request->current_id;
  1267. $compound->save();
  1268. $saved = $compound->save();
  1269. if($saved){
  1270. $gDate = $compound->created_at->format('F Y');
  1271. $historyData = [
  1272. 'tarikh_kumpulan' => $gDate,
  1273. ];
  1274. $subHistory = [
  1275. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1276. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1277. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1278. ];
  1279. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1280. if(!empty($groupByDate)){
  1281. $groupByDate->subhistory()->create($subHistory);
  1282. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1283. }else{
  1284. $history = History::create($historyData);
  1285. $history->subhistory()->create($subHistory);
  1286. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1287. }
  1288. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1289. }else{
  1290. $response = [
  1291. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1292. ];
  1293. return response()->json($response, 200);
  1294. }
  1295. }else{
  1296. $response = [
  1297. 'success' => false, 'message' => 'Tiada kemaskini!',
  1298. ];
  1299. return response()->json($response, 200);
  1300. }
  1301. }
  1302. }else{
  1303. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1304. $compound->status = $request->status;
  1305. $compound->catatan_dari_admin = $request->remark;
  1306. $compound->amount_payment = $request->amount;
  1307. $compound->update_by = $request->current_id;
  1308. $saved = $compound->save();
  1309. if($saved){
  1310. $gDate = $compound->created_at->format('F Y');
  1311. $historyData = [
  1312. 'tarikh_kumpulan' => $gDate,
  1313. ];
  1314. $subHistory = [
  1315. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1316. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1317. '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>",
  1318. ];
  1319. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1320. if(!empty($groupByDate)){
  1321. $groupByDate->subhistory()->create($subHistory);
  1322. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1323. }else{
  1324. $history = History::create($historyData);
  1325. $history->subhistory()->create($subHistory);
  1326. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1327. }
  1328. if($request->status == "Berbayar"){
  1329. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1330. }else{
  1331. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1332. }
  1333. }else{
  1334. $response = [
  1335. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1336. ];
  1337. return response()->json($response, 200);
  1338. }
  1339. }else{
  1340. if($request->remark != ''){
  1341. $compound->catatan_dari_admin = $request->remark;
  1342. $compound->update_by = $request->current_id;
  1343. $compound->save();
  1344. $saved = $compound->save();
  1345. if($saved){
  1346. $gDate = $compound->created_at->format('F Y');
  1347. $historyData = [
  1348. 'tarikh_kumpulan' => $gDate,
  1349. ];
  1350. $subHistory = [
  1351. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1352. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1353. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1354. ];
  1355. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1356. if(!empty($groupByDate)){
  1357. $groupByDate->subhistory()->create($subHistory);
  1358. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1359. }else{
  1360. $history = History::create($historyData);
  1361. $history->subhistory()->create($subHistory);
  1362. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1363. }
  1364. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1365. }else{
  1366. $response = [
  1367. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1368. ];
  1369. return response()->json($response, 200);
  1370. }
  1371. }else{
  1372. $response = [
  1373. 'success' => false, 'message' => 'Tiada kemaskini!',
  1374. ];
  1375. return response()->json($response, 200);
  1376. }
  1377. }
  1378. }
  1379. }else{
  1380. $response = [
  1381. 'success' => false,
  1382. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  1383. ];
  1384. return response()->json($response, 200);
  1385. }
  1386. }
  1387. /**
  1388. * Remove the specified resource from storage.
  1389. *
  1390. * @param int $id
  1391. * @return \Illuminate\Http\Response
  1392. */
  1393. public function destroy($id)
  1394. {
  1395. //
  1396. }
  1397. }