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

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