Dashboard sipadu mbip
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CompoundResourceController.php 69KB

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