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

CompoundResourceController.php 69KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583
  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_n', $jenis)->whereBetween('created_at', array($start->subDays(3), $end->subDays(3)));
  55. }
  56. else if(!empty($day7))
  57. {
  58. $compound = Compound::where('jenis_n', $jenis)->whereBetween('created_at', array($start->subDays(7), $end->subDays(7)));
  59. }
  60. else
  61. {
  62. $compound = Compound::where(function($query) use ($jenis){$query->where('jenis', $jenis)->orWhere('jenis_n', $jenis); })
  63. ->whereBetween('created_at', array($start, $end));
  64. }
  65. if($modul == 'All'){
  66. $compound = $compound;
  67. }else if($modul == '06-07'){
  68. $compound = $compound->where(function($q){
  69. $q->where('modul', '06')->orWhere('modul','07');
  70. });
  71. }else {
  72. $compound = $compound->where('modul', $modul);
  73. }
  74. if($status == 'All'){
  75. $compound = $compound;
  76. }else {
  77. $compound = $compound->where('status', $status);
  78. }
  79. return $compound;
  80. }
  81. private function searchCompoundAllWithoutDate($jenis,$modul,$status,$day3, $day7){
  82. if(!empty($day3))
  83. {
  84. $compound = Compound::where('jenis_n', $jenis)->where('created_at', Carbon::now()->subDays(3));
  85. }
  86. else if(!empty($day7))
  87. {
  88. $compound = Compound::where('jenis_n', $jenis)->where('created_at', Carbon::now()->subDays(7));
  89. }
  90. else
  91. {
  92. $compound = Compound::where('jenis', $jenis)->orWhere('jenis_n', $jenis);
  93. }
  94. if($modul == 'All'){
  95. $compound = $compound;
  96. }else if($modul == '06-07'){
  97. $compound = $compound->where(function($q){
  98. $q->where(function($query){
  99. $query->where('modul', '06')->orWhere('modul','07');
  100. });
  101. });
  102. }else {
  103. $compound = $compound->where('modul', $modul);
  104. }
  105. if($status == 'All'){
  106. $compound = $compound;
  107. }else {
  108. $compound = $compound->where('status', $status);
  109. }
  110. return $compound;
  111. }
  112. private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date,$day3, $day7){
  113. if(!empty($start_date)){
  114. $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date,$day3, $day7);
  115. }else{
  116. $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status,$day3, $day7);
  117. }
  118. if($enforcer == 'All'){
  119. return $compound;
  120. }else {
  121. $compound = $compound->where('dikeluarkan', $enforcer)->orWhere('dikeluarkan_n', $enforcer);
  122. return $compound;
  123. }
  124. }
  125. private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$day3, $day7){
  126. $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date,$day3, $day7);
  127. if($faulty == 'All'){
  128. $compound = $compound->whereIn('jbkod', $department, 'or')->whereIn('jbkod_n', $department);
  129. return $compound;
  130. }else {
  131. $compound = $compound->where('seksyen_kesalahan', $faulty)->orWhere('seksyen_kesalahan_n', $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 = 'Notis_NHN';
  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-09';
  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 = '';
  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. $nested_data = array();
  266. $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();
  267. info($compound);
  268. return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
  269. ->addColumn('index', function($row) {
  270. $curr = Carbon::now();
  271. $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
  272. if($curr->diffInDays($dtC) <= 3){
  273. $html = 'New';
  274. }else{ $html = ''; }
  275. return $html;
  276. })->addColumn('status_kemaskini', function($row) {
  277. $data = '';
  278. if($row['status'] == 'Berbayar'){
  279. if ($row['modul'] == '02') {
  280. $data = '<b>Selesai</b><div style="margin-top: 8px"><span></span><br/></div>';
  281. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  282. }
  283. else{
  284. $data = '<b>'.$row['status'].'</b><div style="margin-top: 8px"><span>Bayaran: </span><br/>';
  285. $data .= 'RM '.$row['amount_payment'].'</div>';
  286. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  287. }
  288. if($row['updated_by'] !== null ){
  289. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  290. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  291. }else {
  292. if(!empty($row['tarikh_bayar']) && $row['tarikh_bayar'] != ''){
  293. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  294. $data .= $row['tarikh_bayar'].' <br/>'.$row['updates_by'].'</div>';
  295. }else {
  296. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  297. $data .= $row['updated_at'].' <br/>'.$row['updates_by'].'</div>';
  298. }
  299. }
  300. }else if($row['status'] == 'Belum Bayar' && $row['updated_by'] !== null){
  301. $data = '<b>'.$row['status'].'</b>';
  302. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  303. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  304. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  305. }else if($row['status'] == 'Batal' && $row['updated_by'] !== null){
  306. $data = '<b>'.$row['status'].'</b>';
  307. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  308. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  309. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  310. }else if($row['status'] == 'Buang' && $row['updated_by'] !== null){
  311. $data = '<b>'.$row['status'].'</b>';
  312. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  313. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  314. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  315. }
  316. else
  317. {
  318. $data = $row['status'];
  319. }
  320. return $data;
  321. })->addColumn('kesalahan', function($row) {
  322. $data = '<b>Seksyen '.$row['faulty_skter'].'</b><br/>'.$row['faulty_name'];
  323. return $data;
  324. })->rawColumns(['index','status_kemaskini','kesalahan'])->make(true);
  325. }
  326. /**
  327. * Show the form for creating a new resource.
  328. *
  329. * @return \Illuminate\Http\Response
  330. */
  331. public function generateNumber($jenis, $tag, $modul)
  332. {
  333. $num= '';
  334. if($modul == '02')
  335. {
  336. //check if theres no 001, start fresh with 0001
  337. if (empty(Compound::where('jenis_n', $jenis)->where('non', $tag.'0001')->first())) {
  338. $num = '0001';
  339. }
  340. else{
  341. //check the lastest compound number stored in dbase filtered by jenis
  342. $notice = Compound::where('jenis_n', $jenis)->withTrashed()->latest()->first();
  343. //sanitize compound number to return only integer
  344. $num = filter_var($notice['non'], FILTER_SANITIZE_NUMBER_INT);
  345. //compulsory increment to store new compound number, WHILE number is found, keep looping
  346. do{
  347. (int)$num += 1;
  348. //add 0s at the fornt if number is less than 1000
  349. if ((strlen((string) $num)) == 1) {
  350. $num = '000'.$num;
  351. }elseif ((strlen((string)$num)) == 2){
  352. $num = '00'.$num;
  353. }elseif ((strlen((string)$num )) == 3) {
  354. $num = '0'.$num;
  355. }
  356. }while(!empty(Compound::where('jenis_n', $jenis)->where('non', $tag.$num)->first()));
  357. }
  358. }else if($modul == '03')
  359. {
  360. //check if theres no 001, start fresh with 0001
  361. if (empty(Compound::where('jenis', $jenis)->where('kpd', $tag.'0001')->first())) {
  362. $num = '0001';
  363. }
  364. else{
  365. //check the lastest compound number stored in dbase filtered by jenis
  366. $compound = Compound::where('jenis', $jenis)->withTrashed()->latest()->first();
  367. //sanitize compound number to return only integer
  368. $num = filter_var($compound['kpd'], FILTER_SANITIZE_NUMBER_INT);
  369. //compulsory increment to store new compound number, WHILE number is found, keep looping
  370. do{
  371. (int)$num += 1;
  372. //add 0s at the fornt if number is less than 1000
  373. if ((strlen((string) $num)) == 1) {
  374. $num = '000'.$num;
  375. }elseif ((strlen((string)$num)) == 2){
  376. $num = '00'.$num;
  377. }elseif ((strlen((string)$num )) == 3) {
  378. $num = '0'.$num;
  379. }
  380. }while(!empty(Compound::where('jenis', $jenis)->where('kpd', $tag.$num)->first()));
  381. }
  382. }
  383. //return kpd with tag
  384. $num = $tag . $num;
  385. return $num;
  386. }
  387. /**
  388. * Store a created compound from notice.
  389. *
  390. * @param \Illuminate\Http\Request $request
  391. * @return \Illuminate\Http\Response
  392. */
  393. public function store(Request $request)
  394. {
  395. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  396. if(empty($staff)){
  397. return $this->sendError('Invalid', 'Staff not existed');
  398. }else {
  399. $saved ='';
  400. $kpd = '';
  401. $no_siri = '';
  402. $data = array();
  403. $faulty = $request->seksyen;
  404. $faulty = Faulty::where('_id',$request->get('seksyen'))->orWhere('nama', 'like', $faulty)->first();
  405. if($request->jenis == 'Parkir')
  406. {
  407. if(!empty($faulty)){
  408. $countKPD = $this->compound->withTrashed()->count();
  409. do {
  410. $countKPD = $countKPD + 1;
  411. } while (!empty(Compound::where("kpd", "=", 'KP'.$countKPD)->first()));
  412. $kpd = 'KP'.$countKPD;
  413. $no_siri = date('yn').'-'.$countKPD;
  414. $fileData = [
  415. 'no_siri' => $no_siri,
  416. ];
  417. //only for compound parkir
  418. $compoundData = [
  419. 'jenis' => 'Parkir',
  420. 'kpd' => 'KPD'.$kpd,
  421. 'nama' => '-',
  422. 'identity' => '-',
  423. 'alamat' => '-',
  424. "no_plate" => strtolower($request->no_plate),
  425. "no_cukai_jalan" => $request->noCukaijalan,
  426. "jenis_kenderaan" => $request->jenisKenderaan,
  427. "model_kenderaan" => $request->modelKenderaan,
  428. "warna_kenderaan" => $request->warnakenderaan,
  429. "nama_kawasan" => $request->namaKawasan,
  430. "nama_taman" => $request->namaTaman,
  431. "nama_jalan" => $request->namaJalan,
  432. "no_parking" => $request->noParking,
  433. "catatan" => $request->catatan,
  434. "lokasi_kejadian" => '-',
  435. 'latlong' => $request->Latlong,
  436. 'jbkod' => $request->jabatan,
  437. 'akta' => $faulty->deed_law_id,
  438. 'seksyen_kesalahan' => $faulty->_id,
  439. 'jumlah_asal_kompaun' => $faulty->amount,
  440. 'jumlah_kemaskini_kompaun' => '-',
  441. 'dikeluarkan' => $staff->_id,
  442. "status" => 'Belum Bayar',
  443. "amount_payment" => '-',
  444. "receipt" => '-',
  445. "modul" => '03',
  446. "penguatkuasa" => '-',
  447. "cpn_created" => Carbon::now(),
  448. ];
  449. $file = ConfidentialFile::create($fileData);
  450. $saved = $file->compound()->create($compoundData);
  451. }
  452. }elseif(($request->jenis == 'Pelbagai_KT') || ($request->jenis == 'Pelbagai_JPB')){
  453. $compound = Compound::where('jenis_n', $request->jenis)->orWhere('non', $request->non)->first();
  454. if(!empty($compound)) {
  455. $saved = '';
  456. if(!($compound->modul == '03' && isset($compound->kpd)))
  457. {
  458. if($request->jenis == 'Pelbagai_KT'){
  459. $kpd = $this->generateNumber($request->jenis, 'KT', '03');
  460. $compound->kpd = $kpd;
  461. $compound->jenis = $request->jenis;
  462. $compound->nama = $request->namaP;
  463. $compound->identity = $request->noIc;
  464. $compound->nama_syarikat = $request->namaS;
  465. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  466. $compound->alamat = $request->alamat;
  467. $compound->lokasi_kejadian = $request->alamat_tempat_kesalahan;
  468. // $compound->no_plate = $request->no_plate;
  469. // $compound->no_cukai_jalan = $request->no_cukai_jalan;
  470. // $compound->nama_kawasan = $request->namaKawasan;
  471. // $compound->nama_taman = $request->namaTaman;
  472. // $compound->nama_jalan = $request->namaJalan;
  473. $compound->catatan = $request->catatan;
  474. $compound->latlong = $request->Latlong;
  475. $compound->akta = $faulty->deed_law_id;
  476. $compound->seksyen_kesalahan = $faulty->_id;
  477. $compound->jumlah_asal_kompaun = $faulty->amount;
  478. $compound->dikeluarkan = $staff->_id;
  479. $compound->status = 'Belum Bayar';
  480. $compound->modul = '03';
  481. $compound->no_akaun_lesen = $request->lesen;
  482. $compound->created_c = Carbon::now();
  483. }elseif($request->jenis == 'Pelbagai_JPB'){
  484. $kpd = $this->generateNumber($request->jenis, 'JPB', '03');
  485. $compound->kpd = $kpd;
  486. $compound->jenis = $request->jenis;
  487. $compound->nama = $request->namaP;
  488. $compound->identity = $request->noIc;
  489. $compound->nama_syarikat = $request->namaS;
  490. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  491. $compound->alamat = $request->alamat;
  492. $compound->lokasi_kejadian = $request->alamat_tempat_kesalahan;
  493. // $compound->no_plate = $request->no_plate;
  494. // $compound->no_cukai_jalan = $request->no_cukai_jalan;
  495. // $compound->nama_kawasan => $request->namaKawasan;
  496. // $compound->nama_taman => $request->namaTaman;
  497. // $compound->nama_jalan => $request->namaJalan;
  498. $compound->catatan = $request->catatan;
  499. $compound->latlong = $request->Latlong;
  500. $compound->akta = $faulty->deed_law_id;
  501. $compound->seksyen_kesalahan = $faulty->_id;
  502. $compound->jumlah_asal_kompaun = $faulty->amount;
  503. $compound->dikeluarkan = $staff->_id;
  504. $compound->status = 'Belum Bayar';
  505. $compound->modul = '03';
  506. $compound->no_akaun_lesen = $request->lesen;
  507. $compound->created_c = Carbon::now();
  508. }
  509. $saved = $compound->save();
  510. }
  511. else
  512. {
  513. return $this->sendResponse('', 'Kompaun ini telah dikeluarkan!');
  514. }
  515. if($saved){
  516. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  517. // if(!empty($compound)){
  518. // dispatch(new UpdateCompoundPrice($kpd));
  519. // $tawaran = '';
  520. // if($compound->jumlah_kemaskini_kompaun != ''){
  521. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  522. // }else{
  523. // $tawaran = $compound->jumlah_asal_kompaun;
  524. // }
  525. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  526. array_push($data, array('kpd' => $kpd));
  527. // $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  528. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  529. // }
  530. }
  531. }
  532. else{
  533. return $this->sendResponse('', 'Kompaun ini tidak dijumpai!');
  534. }
  535. }
  536. }
  537. }
  538. /**
  539. *
  540. * Store a newly created notice
  541. *
  542. **/
  543. public function storeNewNotice(Request $request)
  544. {
  545. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  546. if(empty($staff)){
  547. return $this->sendError('Invalid', 'Staff not existed');
  548. }else {
  549. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  550. if(!empty($faulty)){
  551. $data = array();
  552. $non = '';
  553. // $kpd = '';
  554. $no_siri ='';
  555. $noticeData = [];
  556. if($request->jenis == 'Parkir'){
  557. //for compound numbering
  558. // $countKPD = $this->compound->withTrashed()->count();
  559. // $kpd = 'KPD'.$countKPD;
  560. // $non = 'KPD'.$countKPD;
  561. // $no_siri = date('yn').'-'.$countKPD.'-0';
  562. // $compoundData = [
  563. // 'jenis' => 'Parkir',
  564. // 'kpd' => $kpd,
  565. // 'non' => $non,
  566. // 'nama' => '-',
  567. // 'identity' => '-',
  568. // 'alamat' => '-',
  569. // "no_plate" => strtolower($request->no_plate),
  570. // "no_cukai_jalan" => $request->noCukaijalan,
  571. // "jenis_kenderaan" => $request->jenisKenderaan,
  572. // "model_kenderaan" => $request->modelKenderaan,
  573. // "warna_kenderaan" => $request->warnakenderaan,
  574. // "nama_kawasan" => $request->namaKawasan,
  575. // "nama_taman" => $request->namaTaman,
  576. // "nama_jalan" => $request->namaJalan,
  577. // "no_parking" => $request->noParking,
  578. // "catatan" => $request->catatan,
  579. // "lokasi_kejadian" => '-',
  580. // 'latlong' => $request->Latlong,
  581. // 'jbkod' => $request->jabatan,
  582. // 'akta' => $faulty->deed_law_id,
  583. // 'seksyen_kesalahan' => $faulty->_id,
  584. // 'jumlah_asal_kompaun' => $faulty->amount,
  585. // 'jumlah_kemaskini_kompaun' => '-',
  586. // 'dikeluarkan' => $staff->_id,
  587. // "status" => 'Belum Bayar',
  588. // "amount_payment" => '-',
  589. // "receipt" => '-',
  590. // "modul" => $request->modul,
  591. // "penguatkuasa" => '-',
  592. // "notis_created" => Carbon::now()->toDateTimeString(),
  593. // ];
  594. }elseif($request->jenis == 'Notis_NKG'){
  595. // $kpd = $this->generateNumber($request->jenis, 'KT', '02');
  596. // $non = 'NKG'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  597. $non = $this->generateNumber($request->jenis, 'NKG', '02');
  598. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-1';
  599. $noticeData = [
  600. 'jenis' => 'Pelbagai_KT',
  601. 'jenis_n' => $request->jenis,
  602. 'kpd' => '-',
  603. 'non' => $non,
  604. 'nama' => $request->namaP,
  605. 'identity' => $request->noIc,
  606. 'nama_syarikat' => $request->namaS,
  607. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  608. 'alamat' => $request->alamat,
  609. "nama_kawasan" => $request->namaKawasan,
  610. "nama_taman" => $request->namaTaman,
  611. "nama_jalan" => $request->namaJalan,
  612. "catatan" => $request->butiran_kesalahan,
  613. "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
  614. 'latlong' => $request->Latlong,
  615. 'jbkod' => $request->jabatan,
  616. 'akta_n' => $faulty->deed_law_id,
  617. 'seksyen_kesalahan_n' => $faulty->_id,
  618. 'dikeluarkan_n' => $staff->_id,
  619. "status" => 'Belum Bayar',
  620. "modul" => $request->modul,
  621. "penguatkuasa" => '-',
  622. "no_akaun_lesen" => $request->lesen,
  623. // "maklumat_tambahan" => $request->butiran_kesalahan,
  624. "tindakan" => $request->tindakan,
  625. "tempoh" => $request->tempoh,
  626. "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh),
  627. "created_n" => Carbon::now(),
  628. ];
  629. }elseif($request->jenis == 'Notis_NMH'){
  630. // $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  631. // $non = 'NMH'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  632. $non = $this->generateNumber($request->jenis, 'NMH', '02');
  633. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-2';
  634. $noticeData = [
  635. 'jenis' => 'Pelbagai_JPB',
  636. 'jenis_n' => $request->jenis,
  637. 'kpd' => '-',
  638. 'non' => $non,
  639. 'nama' => $request->namaP,
  640. 'identity' => $request->noIc,
  641. 'nama_syarikat' => $request->namaS,
  642. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  643. 'alamat' => $request->alamat,
  644. "nama_kawasan" => $request->namaKawasan,
  645. "nama_taman" => $request->namaTaman,
  646. "nama_jalan" => $request->namaJalan,
  647. "catatan" => $request->butiran_kesalahan,
  648. "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
  649. 'latlong' => $request->Latlong,
  650. 'jbkod' => $request->jabatan,
  651. 'akta_n' => $faulty->deed_law_id,
  652. 'seksyen_kesalahan_n' => $faulty->_id,
  653. 'dikeluarkan_n' => $staff->_id,
  654. "status" => 'Belum Bayar',
  655. "modul" => $request->modul,
  656. "penguatkuasa" => '-',
  657. "no_akaun_lesen" => $request->lesen,
  658. // "maklumat_tambahan" => $request->butiran_kesalahan,
  659. "tindakan" => $request->tinadkan,
  660. "tempoh" => $request->tempoh,
  661. "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh),
  662. "created_n" => Carbon::now(),
  663. ];
  664. }
  665. elseif($request->jenis == 'Notis_NHN'){
  666. //HN bcs other N stands for notice. compound number no need front N
  667. // $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  668. // $non = 'NHN'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  669. $non = $this->generateNumber($request->jenis, 'NHN', '02' );
  670. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-3';
  671. $noticeData = [
  672. 'jenis' => 'Pelbagai_KT',
  673. 'jenis_n' => $request->jenis,
  674. 'kpd' => '-',
  675. 'non' => $non,
  676. 'nama' => $request->namaP,
  677. 'identity' => $request->noIc,
  678. 'nama_syarikat' => $request->namaS,
  679. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  680. 'alamat' => $request->alamat,
  681. "nama_kawasan" => $request->namaKawasan,
  682. "nama_taman" => $request->namaTaman,
  683. "nama_jalan" => $request->namaJalan,
  684. "catatan" => $request->butiran_kesalahan,
  685. "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
  686. 'latlong' => $request->Latlong,
  687. 'jbkod' => $request->jabatan,
  688. 'akta_n' => $faulty->deed_law_id,
  689. 'seksyen_kesalahan_n' => $faulty->_id,
  690. 'dikeluarkan_n' => $staff->_id,
  691. "status" => 'Belum Bayar',
  692. "modul" => $request->modul,
  693. "penguatkuasa" => '-',
  694. "no_akaun_lesen" => $request->lesen,
  695. // "maklumat_tambahan" => $request->butiran_kesalahan,
  696. // "tindakan" => $request->tindakan,
  697. "tempoh" => $request->tempoh,
  698. "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh),
  699. "created_n" => Carbon::now(),
  700. ];
  701. }
  702. elseif($request->jenis == 'Notis_PA'){
  703. // $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  704. // $non = 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  705. $non = $this->generateNumber($request->jenis, 'PA', '02');
  706. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-4';
  707. $noticeData = [
  708. 'jenis' => 'Pelbagai_KT',
  709. 'jenis_n' => $request->jenis,
  710. 'kpd' => '-',
  711. 'non' => $non,
  712. 'nama' => $request->namaP,
  713. 'identity' => $request->noIc,
  714. 'nama_syarikat' => $request->namaS,
  715. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  716. 'alamat' => $request->alamat,
  717. "nama_kawasan" => $request->namaKawasan,
  718. "nama_taman" => $request->namaTaman,
  719. "nama_jalan" => $request->namaJalan,
  720. "catatan" => $request->butiran_kesalahan,
  721. "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
  722. 'latlong' => $request->Latlong,
  723. 'jbkod' => $request->jabatan,
  724. 'akta_n' => $faulty->deed_law_id,
  725. 'seksyen_kesalahan_n' => $faulty->_id,
  726. 'dikeluarkan_n' => $staff->_id,
  727. "status" => 'Belum Bayar',
  728. "modul" => $request->modul,
  729. "penguatkuasa" => '-',
  730. "no_akaun_lesen" => $request->lesen,
  731. // "maklumat_tambahan" => $request->butiran_kesalahan,
  732. "tindakan" => $request->tindakan,
  733. "tempoh" => $request->tempoh,
  734. "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh),
  735. "created_n" => Carbon::now(),
  736. "bil_haiwan" => $request->bil_haiwan,
  737. ];
  738. }elseif($request->jenis == 'Notis_NPPM'){
  739. // $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  740. // $non = 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  741. $non = $this->generateNumber($request->jenis, 'NPPM', '02');
  742. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-4';
  743. $noticeData = [
  744. 'jenis' => 'Pelbagai_KT',
  745. 'jenis_n' => $request->jenis,
  746. 'kpd' => '-',
  747. 'non' => $non,
  748. 'nama' => $request->namaP,
  749. 'identity' => $request->noIc,
  750. 'nama_syarikat' => $request->namaS,
  751. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  752. 'alamat' => $request->alamat,
  753. "nama_kawasan" => $request->namaKawasan,
  754. "nama_taman" => $request->namaTaman,
  755. "nama_jalan" => $request->namaJalan,
  756. "catatan" => $request->butiran_kesalahan,
  757. "lokasi_kejadian" => $request->alamat_tempat_kesalahan,
  758. 'latlong' => $request->Latlong,
  759. 'jbkod' => $request->jabatan,
  760. 'akta_n' => $faulty->deed_law_id,
  761. 'seksyen_kesalahan_n' => $faulty->_id,
  762. 'dikeluarkan_n' => $staff->_id,
  763. "status" => 'Belum Bayar',
  764. "modul" => $request->modul,
  765. "penguatkuasa" => '-',
  766. "no_akaun_lesen" => $request->lesen,
  767. // "maklumat_tambahan" => $request->butiran_kesalahan,
  768. "tindakan" => $request->tindakan,
  769. "tempoh" => $request->tempoh,
  770. "tempoh_tarikh" => Carbon::now()->addDays($request->tempoh),
  771. "created_n" => Carbon::now(),
  772. ];
  773. }
  774. $fileData = [
  775. 'no_siri' => $no_siri,
  776. ];
  777. $file = ConfidentialFile::create($fileData);
  778. $saved = $file->compound()->create($noticeData);
  779. if($saved){
  780. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  781. // if(!empty($compound)){
  782. // dispatch(new UpdateCompoundPrice($kpd));
  783. // $tawaran = '';
  784. // if($compound->jumlah_kemaskini_kompaun != ''){
  785. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  786. // }else{
  787. // $tawaran = $compound->jumlah_asal_kompaun;
  788. // }
  789. $this->dispatch(new StoreNotice($request->all(), $non, $staff->_id, $no_siri));
  790. //mobile already accept 'kpd' string, so no need to change string name to 'notis'.
  791. array_push($data, array(
  792. 'kpd' => $non,
  793. 'non' => $non
  794. ));
  795. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  796. // }
  797. }
  798. }
  799. }
  800. }
  801. /**
  802. * Store a newly created compound (parkir, KT, JPB).
  803. *
  804. * @param \Illuminate\Http\Request $request
  805. * @return \Illuminate\Http\Response
  806. */
  807. public function storeNewCompound(Request $request)
  808. {
  809. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  810. if(empty($staff)){
  811. return $this->sendError('Invalid', 'Staff not existed');
  812. }else {
  813. $data = array();
  814. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  815. if(!empty($faulty)){
  816. $kpd = '';
  817. $no_siri ='';
  818. // $countKPD = $this->compound->withTrashed()->count();
  819. // do {
  820. // $countKPD = $countKPD + 1;
  821. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  822. // $kpd = $countKPD;
  823. // $no_siri = date('yn').'-'.$countKPD;
  824. // $fileData = [
  825. // 'no_siri' => $no_siri,
  826. // ];
  827. if($request->jenis == 'Parkir')
  828. {
  829. //for compound numbering
  830. $countKPD = $this->compound->where('jenis','Parkir')->withTrashed()->count();
  831. $kpd = 'KPD'.$countKPD;
  832. $no_siri = date('yn').'-'.$countKPD.'-0';
  833. //only for compound parkir
  834. $compoundData = [
  835. 'jenis' => 'Parkir',
  836. 'kpd' => $kpd,
  837. 'nama' => '-',
  838. 'identity' => '-',
  839. 'alamat' => '-',
  840. "no_plate" => strtolower($request->no_plate),
  841. "no_cukai_jalan" => $request->noCukaijalan,
  842. "jenis_kenderaan" => $request->jenisKenderaan,
  843. "model_kenderaan" => $request->modelKenderaan,
  844. "warna_kenderaan" => $request->warnakenderaan,
  845. "nama_kawasan" => $request->namaKawasan,
  846. "nama_taman" => $request->namaTaman,
  847. "nama_jalan" => $request->namaJalan,
  848. "no_parking" => $request->noParking,
  849. "catatan" => $request->catatan,
  850. "lokasi_kejadian" => '-',
  851. 'latlong' => $request->Latlong,
  852. 'jbkod' => $request->jabatan,
  853. 'akta' => $faulty->deed_law_id,
  854. 'seksyen_kesalahan' => $faulty->_id,
  855. 'jumlah_asal_kompaun' => $faulty->amount,
  856. 'jumlah_kemaskini_kompaun' => '-',
  857. 'dikeluarkan' => $staff->_id,
  858. "status" => 'Belum Bayar',
  859. "amount_payment" => '-',
  860. "receipt" => '-',
  861. "modul" => '03',
  862. "penguatkuasa" => '-',
  863. "created_c" => Carbon::now(),
  864. ];
  865. }
  866. if ($request->jenis == 'Pelbagai_KT') {
  867. $kpd = $this->generateNumber($request->jenis, 'KT', '03');
  868. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  869. $compoundData = [
  870. 'jenis' => $request->jenis,
  871. 'kpd' => $kpd,
  872. 'nama' => $request->namaP,
  873. 'identity' => $request->noIc,
  874. 'nama_syarikat' => $request->namaS,
  875. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  876. 'alamat' => $request->alamat,
  877. "lokasi_kejadian" => $request->alamat_tempat_pesalah,
  878. "nama_kawasan" => $request->namaKawasan,
  879. "nama_taman" => $request->namaTaman,
  880. "nama_jalan" => $request->namaJalan,
  881. 'latlong' => $request->Latlong,
  882. 'jbkod' => $request->jabatan,
  883. 'akta' => $faulty->deed_law_id,
  884. 'seksyen_kesalahan' => $faulty->_id,
  885. 'jumlah_asal_kompaun' => $faulty->amount,
  886. 'jumlah_kemaskini_kompaun' => '-',
  887. 'dikeluarkan' => $staff->_id,
  888. "status" => 'Belum Bayar',
  889. "amount_payment" => '-',
  890. "receipt" => '-',
  891. "modul" => $request->modul,
  892. "penguatkuasa" => '-',
  893. "no_akaun_lesen" => $request->lesen,
  894. "created_c" => Carbon::now(),
  895. ];
  896. }
  897. elseif ($request->jenis == 'Pelbagai_JPB') {
  898. $kpd = $this->generateNumber($request->jenis, 'JPB', '03');
  899. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  900. $compoundData = [
  901. 'jenis' => $request->jenis,
  902. 'kpd' => $kpd,
  903. 'nama' => $request->namaP,
  904. 'identity' => $request->noIc,
  905. 'nama_syarikat' => $request->namaS,
  906. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  907. 'alamat' => $request->alamat,
  908. "lokasi_kejadian" => $request->alamat_tempat_pesalah,
  909. "nama_kawasan" => $request->namaKawasan,
  910. "nama_taman" => $request->namaTaman,
  911. "nama_jalan" => $request->namaJalan,
  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_akaun_lesen" => $request->lesen,
  925. "created_c" => Carbon::now(),
  926. ];
  927. }
  928. $fileData = [
  929. 'no_siri' => $no_siri,
  930. ];
  931. $file = ConfidentialFile::create($fileData);
  932. $saved = $file->compound()->create($compoundData);
  933. if($saved){
  934. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  935. // if(!empty($compound)){
  936. // dispatch(new UpdateCompoundPrice($kpd));
  937. // $tawaran = '';
  938. // if($compound->jumlah_kemaskini_kompaun != ''){
  939. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  940. // }else{
  941. // $tawaran = $compound->jumlah_asal_kompaun;
  942. // }
  943. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  944. array_push($data, array('kpd' => $kpd));
  945. // $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  946. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  947. }
  948. return $this->sendError('', 'Tidak berjaya simpan rekod kompaun!');
  949. }
  950. return $this->sendResponse('Tidak Berjaya!', 'Kesalahan tidak dijumpai!');
  951. }
  952. }
  953. /**
  954. * Display the specified resource.
  955. *
  956. * @param int $id
  957. * @return \Illuminate\Http\Response
  958. */
  959. public function show($id)
  960. {
  961. //
  962. }
  963. /**
  964. * Show the form for editing the specified resource.
  965. *
  966. * @param int $id
  967. * @return \Illuminate\Http\Response
  968. */
  969. public function edit($id)
  970. {
  971. //
  972. }
  973. /**
  974. * Update the specified resource in storage.
  975. *
  976. * @param \Illuminate\Http\Request $request
  977. * @param int $id
  978. * @return \Illuminate\Http\Response
  979. */
  980. public function update(Request $request, $id)
  981. {
  982. //
  983. }
  984. public function updateStatusNoticeViaDashboard(Request $request)
  985. {
  986. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  987. $staff = StaffDetail::find($request->current_id);
  988. if(!empty($compound) && !empty($staff)){
  989. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  990. if($compound->status != $request->status){
  991. $compound->status = $request->status;
  992. $compound->catatan_dari_admin = $request->remark;
  993. $compound->update_by = $request->current_id;
  994. $saved = $compound->save();
  995. if($saved){
  996. $gDate = $compound->created_at->format('F Y');
  997. $historyData = [
  998. 'tarikh_kumpulan' => $gDate,
  999. ];
  1000. $subHistory = [
  1001. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1002. 'tajuk' => "Status notis ".$compound->kpd. " telah dikemaskini",
  1003. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1004. ];
  1005. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1006. if(!empty($groupByDate)){
  1007. $groupByDate->subhistory()->create($subHistory);
  1008. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1009. }else{
  1010. $history = History::create($historyData);
  1011. $history->subhistory()->create($subHistory);
  1012. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1013. }
  1014. if($request->status == "Berbayar"){
  1015. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1016. }else{
  1017. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1018. }
  1019. }else{
  1020. $response = [
  1021. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1022. ];
  1023. return response()->json($response, 200);
  1024. }
  1025. }else{
  1026. if($request->remark != ''){
  1027. $compound->catatan_dari_admin = $request->remark;
  1028. $compound->update_by = $request->current_id;
  1029. $compound->save();
  1030. $saved = $compound->save();
  1031. if($saved){
  1032. $gDate = $compound->created_at->format('F Y');
  1033. $historyData = [
  1034. 'tarikh_kumpulan' => $gDate,
  1035. ];
  1036. $subHistory = [
  1037. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1038. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1039. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1040. ];
  1041. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1042. if(!empty($groupByDate)){
  1043. $groupByDate->subhistory()->create($subHistory);
  1044. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1045. }else{
  1046. $history = History::create($historyData);
  1047. $history->subhistory()->create($subHistory);
  1048. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1049. }
  1050. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1051. }else{
  1052. $response = [
  1053. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1054. ];
  1055. return response()->json($response, 200);
  1056. }
  1057. }else{
  1058. $response = [
  1059. 'success' => false, 'message' => 'Tiada kemaskini!',
  1060. ];
  1061. return response()->json($response, 200);
  1062. }
  1063. }
  1064. }else{
  1065. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1066. $compound->status = $request->status;
  1067. $compound->catatan_dari_admin = $request->remark;
  1068. // $compound->amount_payment = $request->amount;
  1069. $compound->update_by = $request->current_id;
  1070. $saved = $compound->save();
  1071. if($saved){
  1072. $gDate = $compound->created_at->format('F Y');
  1073. $historyData = [
  1074. 'tarikh_kumpulan' => $gDate,
  1075. ];
  1076. $subHistory = [
  1077. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1078. 'tajuk' => "Status notis telah dikemaskini",
  1079. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1080. ];
  1081. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1082. if(!empty($groupByDate)){
  1083. $groupByDate->subhistory()->create($subHistory);
  1084. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1085. }else{
  1086. $history = History::create($historyData);
  1087. $history->subhistory()->create($subHistory);
  1088. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1089. }
  1090. if($request->status == "Berbayar"){
  1091. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1092. }else{
  1093. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1094. }
  1095. }else{
  1096. $response = [
  1097. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1098. ];
  1099. return response()->json($response, 200);
  1100. }
  1101. }else{
  1102. if($request->remark != ''){
  1103. $compound->catatan_dari_admin = $request->remark;
  1104. $compound->update_by = $request->current_id;
  1105. $compound->save();
  1106. $saved = $compound->save();
  1107. if($saved){
  1108. $gDate = $compound->created_at->format('F Y');
  1109. $historyData = [
  1110. 'tarikh_kumpulan' => $gDate,
  1111. ];
  1112. $subHistory = [
  1113. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1114. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1115. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1116. ];
  1117. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1118. if(!empty($groupByDate)){
  1119. $groupByDate->subhistory()->create($subHistory);
  1120. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1121. }else{
  1122. $history = History::create($historyData);
  1123. $history->subhistory()->create($subHistory);
  1124. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1125. }
  1126. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1127. }else{
  1128. $response = [
  1129. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1130. ];
  1131. return response()->json($response, 200);
  1132. }
  1133. }else{
  1134. $response = [
  1135. 'success' => false, 'message' => 'Tiada kemaskini!',
  1136. ];
  1137. return response()->json($response, 200);
  1138. }
  1139. }
  1140. }
  1141. }else{
  1142. $response = [
  1143. 'success' => false,
  1144. 'message' => 'Notis ini tidak dijumpai / staff tidak ditemui',
  1145. ];
  1146. return response()->json($response, 200);
  1147. }
  1148. }
  1149. public function updateStatusPaymentViaDashboard(Request $request)
  1150. {
  1151. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1152. $staff = StaffDetail::find($request->current_id);
  1153. if(!empty($compound) && !empty($staff)){
  1154. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1155. if($compound->status != $request->status){
  1156. $compound->status = $request->status;
  1157. $compound->catatan_dari_admin = $request->remark;
  1158. $compound->amount_payment = $request->amount;
  1159. $compound->update_by = $request->current_id;
  1160. $saved = $compound->save();
  1161. if($saved){
  1162. $gDate = $compound->created_at->format('F Y');
  1163. $historyData = [
  1164. 'tarikh_kumpulan' => $gDate,
  1165. ];
  1166. $subHistory = [
  1167. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1168. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1169. '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>",
  1170. ];
  1171. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1172. if(!empty($groupByDate)){
  1173. $groupByDate->subhistory()->create($subHistory);
  1174. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1175. }else{
  1176. $history = History::create($historyData);
  1177. $history->subhistory()->create($subHistory);
  1178. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1179. }
  1180. if($request->status == "Berbayar"){
  1181. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1182. }else{
  1183. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1184. }
  1185. }else{
  1186. $response = [
  1187. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1188. ];
  1189. return response()->json($response, 200);
  1190. }
  1191. }else{
  1192. if($request->remark != ''){
  1193. $compound->catatan_dari_admin = $request->remark;
  1194. $compound->update_by = $request->current_id;
  1195. $compound->save();
  1196. $saved = $compound->save();
  1197. if($saved){
  1198. $gDate = $compound->created_at->format('F Y');
  1199. $historyData = [
  1200. 'tarikh_kumpulan' => $gDate,
  1201. ];
  1202. $subHistory = [
  1203. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1204. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1205. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1206. ];
  1207. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1208. if(!empty($groupByDate)){
  1209. $groupByDate->subhistory()->create($subHistory);
  1210. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1211. }else{
  1212. $history = History::create($historyData);
  1213. $history->subhistory()->create($subHistory);
  1214. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1215. }
  1216. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1217. }else{
  1218. $response = [
  1219. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1220. ];
  1221. return response()->json($response, 200);
  1222. }
  1223. }else{
  1224. $response = [
  1225. 'success' => false, 'message' => 'Tiada kemaskini!',
  1226. ];
  1227. return response()->json($response, 200);
  1228. }
  1229. }
  1230. }else{
  1231. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1232. $compound->status = $request->status;
  1233. $compound->catatan_dari_admin = $request->remark;
  1234. $compound->amount_payment = $request->amount;
  1235. $compound->update_by = $request->current_id;
  1236. $saved = $compound->save();
  1237. if($saved){
  1238. $gDate = $compound->created_at->format('F Y');
  1239. $historyData = [
  1240. 'tarikh_kumpulan' => $gDate,
  1241. ];
  1242. $subHistory = [
  1243. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1244. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1245. '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>",
  1246. ];
  1247. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1248. if(!empty($groupByDate)){
  1249. $groupByDate->subhistory()->create($subHistory);
  1250. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1251. }else{
  1252. $history = History::create($historyData);
  1253. $history->subhistory()->create($subHistory);
  1254. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1255. }
  1256. if($request->status == "Berbayar"){
  1257. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1258. }else{
  1259. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1260. }
  1261. }else{
  1262. $response = [
  1263. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1264. ];
  1265. return response()->json($response, 200);
  1266. }
  1267. }else{
  1268. if($request->remark != ''){
  1269. $compound->catatan_dari_admin = $request->remark;
  1270. $compound->update_by = $request->current_id;
  1271. $compound->save();
  1272. $saved = $compound->save();
  1273. if($saved){
  1274. $gDate = $compound->created_at->format('F Y');
  1275. $historyData = [
  1276. 'tarikh_kumpulan' => $gDate,
  1277. ];
  1278. $subHistory = [
  1279. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1280. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1281. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1282. ];
  1283. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1284. if(!empty($groupByDate)){
  1285. $groupByDate->subhistory()->create($subHistory);
  1286. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1287. }else{
  1288. $history = History::create($historyData);
  1289. $history->subhistory()->create($subHistory);
  1290. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1291. }
  1292. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1293. }else{
  1294. $response = [
  1295. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1296. ];
  1297. return response()->json($response, 200);
  1298. }
  1299. }else{
  1300. $response = [
  1301. 'success' => false, 'message' => 'Tiada kemaskini!',
  1302. ];
  1303. return response()->json($response, 200);
  1304. }
  1305. }
  1306. }
  1307. }else{
  1308. $response = [
  1309. 'success' => false,
  1310. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  1311. ];
  1312. return response()->json($response, 200);
  1313. }
  1314. }
  1315. /**
  1316. * Remove the specified resource from storage.
  1317. *
  1318. * @param int $id
  1319. * @return \Illuminate\Http\Response
  1320. */
  1321. public function destroy($id)
  1322. {
  1323. //
  1324. }
  1325. }