Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CompoundResourceController.php 73KB

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