Dashboard sipadu mbip
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CompoundResourceController.php 79KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Support\Facades\Log;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Api\BaseController;
  6. use Carbon\Carbon;
  7. use App\Model\Staff;
  8. use App\Model\StaffDetail;
  9. use App\Model\Module\Compound;
  10. use App\Model\Module\Department;
  11. use App\Model\Module\DeedLaw;
  12. use App\Model\Module\Faulty;
  13. use App\Model\Module\ConfidentialFile;
  14. use App\Model\Module\History;
  15. use App\Model\Module\SubHistory;
  16. use App\Model\Module\Memo;
  17. use App\Model\Module\Attachment;
  18. use App\Jobs\StoreCompound;
  19. use App\Jobs\StoreNotice;
  20. use App\Jobs\StoreCompoundEPBT;
  21. use App\Jobs\UpdateCompoundPrice;
  22. use App\Http\Resources\CompoundResource;
  23. class CompoundResourceController extends BaseController
  24. {
  25. /**
  26. * @var ServiceCategory
  27. */
  28. protected $compound;
  29. /**
  30. * ServiceController constructor.
  31. *
  32. * @param ServiceCategory $ServiceCategory
  33. */
  34. public function __construct(Compound $compound)
  35. {
  36. $this->compound = $compound;
  37. }
  38. /**
  39. * Display a listing of the resource.
  40. *
  41. * @return \Illuminate\Http\Response
  42. */
  43. private function searchCompoundAll($jenis,$modul,$status,$start_date,$end_date,$day3, $day7){
  44. $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
  45. $start = $dateS->copy()->startOfDay();
  46. if($end_date != ''){
  47. $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
  48. $end = $dateE->copy()->endOfDay();
  49. }else{
  50. $end = $dateS->copy()->endOfDay();
  51. }
  52. if(!empty($day3))
  53. {
  54. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start->subDays(3), $end->subDays(3)));
  55. }
  56. else if(!empty($day7))
  57. {
  58. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start->subDays(7), $end->subDays(7)));
  59. }
  60. else
  61. {
  62. $compound = Compound::where('jenis', $jenis)->whereBetween('created_at', array($start, $end));
  63. }
  64. if($modul == 'All'){
  65. $compound = $compound;
  66. }else if($modul == '06-07'){
  67. $compound = $compound->where(function($q){
  68. // $q->where(function($query){
  69. $q->where('modul', '06')->orWhere('modul','07');
  70. // });
  71. });
  72. }else {
  73. $compound = $compound->where('modul', $modul);
  74. }
  75. if($status == 'All'){
  76. $compound = $compound;
  77. }else {
  78. $compound = $compound->where('status', $status);
  79. }
  80. return $compound;
  81. }
  82. private function searchCompoundAllWithoutDate($jenis,$modul,$status,$day3, $day7){
  83. if(!empty($day3))
  84. {
  85. $compound = Compound::where('jenis', $jenis)->where('created_at', Carbon::now()->subDays(3));
  86. }
  87. else if(!empty($day7))
  88. {
  89. $compound = Compound::where('jenis', $jenis)->where('created_at', Carbon::now()->subDays(7));
  90. }
  91. else
  92. {
  93. $compound = Compound::where('jenis', $jenis);
  94. }
  95. if($modul == 'All'){
  96. $compound = $compound;
  97. }else if($modul == '06-07'){
  98. $compound = $compound->where(function($q){
  99. $q->where(function($query){
  100. $query->where('modul', '06')->orWhere('modul','07');
  101. });
  102. });
  103. }else {
  104. $compound = $compound->where('modul', $modul);
  105. }
  106. if($status == 'All'){
  107. $compound = $compound;
  108. }else {
  109. $compound = $compound->where('status', $status);
  110. }
  111. return $compound;
  112. }
  113. private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date,$day3, $day7){
  114. if(!empty($start_date)){
  115. $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date,$day3, $day7);
  116. }else{
  117. $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status,$day3, $day7);
  118. }
  119. if($enforcer == 'All'){
  120. return $compound;
  121. }else {
  122. $compound = $compound->where('dikeluarkan', $enforcer);
  123. return $compound;
  124. }
  125. }
  126. private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$day3, $day7){
  127. $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date,$day3, $day7);
  128. if($faulty == 'All'){
  129. return $compound->whereIn('jbkod',$department);
  130. }else {
  131. $compound = $compound->where('seksyen_kesalahan', $faulty);
  132. return $compound;
  133. }
  134. }
  135. private function searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$day3, $day7){
  136. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$day3, $day7);
  137. if(!empty($plate_no)){
  138. $compound = $compound->where('no_plate',$plate_no);
  139. return $compound;
  140. }else{
  141. return $compound;
  142. }
  143. }
  144. private function searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$day3, $day7){
  145. $compound = $this->searchPlateNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$day3, $day7);
  146. if(!empty($kpd)){
  147. if($modul == '02'){
  148. $compound = $compound->where('kpd',$kpd)->orWhere('non', $kpd);
  149. }
  150. else{
  151. $compound = $compound->where('kpd',$kpd);
  152. }
  153. return $compound;
  154. }else{
  155. $compound = $compound->whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal']);
  156. return $compound;
  157. }
  158. }
  159. private function searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$day3, $day7){
  160. $compound = $this->searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$day3, $day7);
  161. if(!empty($company_no)){
  162. $compound = $compound->where('no_daftar_syarikat','LIKE',$company_no);
  163. return $compound;
  164. }else{
  165. return $compound;
  166. }
  167. }
  168. private function searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$day3, $day7){
  169. $compound = $this->searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$day3, $day7);
  170. if(!empty($nric)){
  171. $compound = $compound->where('identity',$nric);
  172. return $compound;
  173. }else{
  174. return $compound;
  175. }
  176. }
  177. private function searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$day3, $day7){
  178. $compound = $this->searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$day3, $day7);
  179. if(!empty($license)){
  180. $compound = $compound->where('no_akaun_lesen', 'exists', true)->where('no_akaun_lesen',$license);
  181. return $compound;
  182. }else{
  183. return $compound;
  184. }
  185. }
  186. private function searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$day3, $day7){
  187. $compound = $this->searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$day3, $day7);
  188. if(!empty($namaP)){
  189. $compound = $compound->where('nama', 'LIKE', "%{$namaP}%");
  190. return $compound;
  191. }else{
  192. return $compound;
  193. }
  194. }
  195. private function searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name,$day3, $day7){
  196. $compound = $this->searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$day3, $day7);
  197. if(!empty($company_name)){
  198. $compound = $compound->where('nama_syarikat', 'exists', true)->where('nama_syarikat', 'LIKE', '%{$company_name%}');
  199. return $compound;
  200. }else{
  201. return $compound;
  202. }
  203. }
  204. public function index(Request $request)
  205. {
  206. // $per_page = '';
  207. // $kpd = '';
  208. // $modul = '02';
  209. // $status = 'All';
  210. // $jenis = 'Pelbagai_JPB';
  211. // if(!empty($request->department)){
  212. // $department = array (
  213. // 0 => '5df355f891d6e66b9c5e626d',
  214. // 1 => '5df721c5cde7fd741433c6b2',
  215. // 2 => '5df722a24636f4594f4a3c3d',
  216. // 3 => '5f17a31795dbfd3320761bfe',
  217. // 4 => '5f3b872fea58cb3c1b0e7b8d',
  218. // );
  219. // }else {
  220. // $department = [];
  221. // }
  222. // // $start_date = '';
  223. // // $end_date = '';
  224. // $start_date = '2020-09-29';
  225. // $end_date = '2020-10-01';
  226. // $enforcer = 'All';
  227. // $faulty = 'All';
  228. // $plate_no = strtolower('');
  229. // $company_no = strtolower('');
  230. // $nric = '';
  231. // $license = '';
  232. // $namaP = '';
  233. // $company_name = '';
  234. // $day3 = 3;
  235. // $day7 = '';
  236. /////////////////////////////////////////////////////////////////////////////////
  237. $per_page = $request->per_page;
  238. $kpd = $request->kpd;
  239. $modul = $request->modul;
  240. $status = $request->status;
  241. $jenis = $request->type;
  242. if(!empty($request->department)){
  243. $department = json_decode($request->department);
  244. }else {
  245. $department = [];
  246. }
  247. $start_date = $request->start_date;
  248. $end_date = $request->end_date;
  249. $enforcer = $request->enforcer;
  250. $faulty = $request->faulty;
  251. $plate_no = strtolower($request->plate_no);
  252. $company_no = strtolower($request->company_no);
  253. $nric = $request->nric;
  254. $license = $request->license;
  255. $namaP = $request->nameP;
  256. $company_name = $request->company_name;
  257. $day3='';
  258. $day7='';
  259. if ($request->has('day3')) {
  260. $day3 = $request->day3; //has() checks if param exist and filled
  261. }
  262. if ($request->has('day7')) {
  263. $day3 = $request->day7; //has() checks if param exist and filled
  264. }
  265. // if (!empty($start_date)) {
  266. // }
  267. $nested_data = array();
  268. $compound = $this->searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name, $day3, $day7)->orderBy('created_at','ASC')->get();
  269. // info($compound);
  270. return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
  271. ->addColumn('index', function($row) {
  272. $curr = Carbon::now();
  273. $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
  274. if($curr->diffInDays($dtC) <= 3){
  275. $html = 'New';
  276. }else{ $html = ''; }
  277. return $html;
  278. })->addColumn('status_kemaskini', function($row) {
  279. $data = '';
  280. if($row['status'] == 'Berbayar'){
  281. if ($row['modul'] == '02') {
  282. $data = '<b>Selesai</b><div style="margin-top: 8px"><span></span><br/></div>';
  283. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  284. }
  285. else{
  286. $data = '<b>'.$row['status'].'</b><div style="margin-top: 8px"><span>Bayaran: </span><br/>';
  287. $data .= 'RM '.$row['amount_payment'].'</div>';
  288. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  289. }
  290. if($row['updated_by'] !== null ){
  291. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  292. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  293. }else {
  294. if(!empty($row['tarikh_bayar']) && $row['tarikh_bayar'] != ''){
  295. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  296. $data .= $row['tarikh_bayar'].' <br/>'.$row['updates_by'].'</div>';
  297. }else {
  298. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  299. $data .= $row['updated_at'].' <br/>'.$row['updates_by'].'</div>';
  300. }
  301. }
  302. }else if($row['status'] == 'Belum Bayar' && $row['updated_by'] !== null){
  303. $data = '<b>'.$row['status'].'</b>';
  304. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  305. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  306. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  307. }else if($row['status'] == 'Batal' && $row['updated_by'] !== null){
  308. $data = '<b>'.$row['status'].'</b>';
  309. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  310. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  311. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  312. }else if($row['status'] == 'Buang' && $row['updated_by'] !== null){
  313. $data = '<b>'.$row['status'].'</b>';
  314. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  315. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  316. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  317. }
  318. else
  319. {
  320. $data = $row['status'];
  321. }
  322. return $data;
  323. })->addColumn('kesalahan', function($row) {
  324. $data = '<b>Seksyen '.$row['faulty_skter'].'</b><br/>'.$row['faulty_name'];
  325. return $data;
  326. })->rawColumns(['index','status_kemaskini','kesalahan'])->make(true);
  327. }
  328. /**
  329. * Show the form for creating a new resource.
  330. *
  331. * @return \Illuminate\Http\Response
  332. */
  333. public function 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. "cpn_created" => 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') || ($request->jenis == 'Pelbagai_PA') || ($request->jenis == 'Pelbagai_LESEN')){
  455. $kpd = $request->kpd;
  456. $compound = Compound::where('jenis', $request->jenis)->where('kpd', $kpd)->first();
  457. info($compound);
  458. if(!empty($compound)) {
  459. $saved = '';
  460. if($compound->modul != '03')
  461. {
  462. if($request->jenis == 'Pelbagai_KT'){
  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->no_plate = $request->no_plate;
  470. // $compound->no_cukai_jalan = $request->no_cukai_jalan;
  471. // $compound->nama_kawasan = $request->namaKawasan;
  472. // $compound->nama_taman = $request->namaTaman;
  473. // $compound->nama_jalan = $request->namaJalan;
  474. $compound->catatan = $request->catatan;
  475. $compound->latlong = $request->Latlong;
  476. $compound->akta = $faulty->deed_law_id;
  477. $compound->seksyen_kesalahan = $faulty->_id;
  478. $compound->jumlah_asal_kompaun = $faulty->amount;
  479. $compound->dikeluarkan = $staff->_id;
  480. $compound->status = 'Belum Bayar';
  481. $compound->modul = '03';
  482. $compound->no_telefon = $request->tel;
  483. $compound->no_akaun_lesen = $request->lesen;
  484. $compound->created_c = Carbon::now()->toDateTimeString();
  485. }elseif($request->jenis == 'Pelbagai_JPB'){
  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->no_plate = $request->no_plate;
  493. // $compound->no_cukai_jalan = $request->no_cukai_jalan;
  494. // $compound->nama_kawasan => $request->namaKawasan;
  495. // $compound->nama_taman => $request->namaTaman;
  496. // $compound->nama_jalan => $request->namaJalan;
  497. $compound->catatan = $request->catatan;
  498. $compound->latlong = $request->Latlong;
  499. $compound->akta = $faulty->deed_law_id;
  500. $compound->seksyen_kesalahan = $faulty->_id;
  501. $compound->jumlah_asal_kompaun = $faulty->amount;
  502. $compound->dikeluarkan = $staff->_id;
  503. $compound->status = 'Belum Bayar';
  504. $compound->modul = '03';
  505. $compound->no_telefon = $request->tel;
  506. $compound->no_akaun_lesen = $request->lesen;
  507. $compound->created_c = Carbon::now()->toDateTimeString();
  508. }
  509. // }elseif($request->jenis == 'Pelbagai_PA'){
  510. // $compound->jenis = $request->jenis;
  511. // $compound->nama = $request->namaP;
  512. // $compound->identity = $request->noIc;
  513. // $compound->nama_syarikat = $request->namaS;
  514. // $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  515. // $compound->alamat = $request->alamat;
  516. // // $compound->no_plate = $request->no_plate;
  517. // // $compound->no_cukai_jalan = $request->no_cukai_jalan;
  518. // // $compound->nama_kawasan = $request->namaKawasan;
  519. // // $compound->nama_taman = $request->namaTaman;
  520. // // $compound->nama_jalan = $request->namaJalan;
  521. // $compound->catatan = $request->catatan;
  522. // $compound->latlong = $request->Latlong;
  523. // $compound->akta = $faulty->deed_law_id;
  524. // $compound->seksyen_kesalahan = $faulty->_id;
  525. // $compound->jumlah_asal_kompaun = $faulty->amount;
  526. // $compound->dikeluarkan = $staff->_id;
  527. // $compound->status = 'Belum Bayar';
  528. // $compound->modul = '03';
  529. // $compound->no_telefon = $request->tel;
  530. // $compound->no_akaun_lesen = $request->lesen;
  531. // $compound->bil_haiwan = $request->lesen;
  532. // $compound->created_c = Carbon::now()->toDateTimeString();
  533. // }elseif($request->jenis == 'Pelbagai_LESEN'){
  534. // $compound->jenis = $request->jenis;
  535. // $compound->nama = $request->namaP;
  536. // $compound->identity = $request->noIc;
  537. // $compound->nama_syarikat = $request->namaS;
  538. // $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  539. // $compound->alamat = $request->alamat;
  540. // $compound->no_plate = $request->no_plate;
  541. // $compound->no_cukai_jalan = $request->no_cukai_jalan;
  542. // // $compound->nama_kawasan = $request->namaKawasan;
  543. // // $compound->nama_taman = $request->namaTaman;
  544. // // $compound->nama_jalan = $request->namaJalan;
  545. // $compound->catatan = $request->catatan;
  546. // $compound->latlong = $request->Latlong;
  547. // $compound->akta = $faulty->deed_law_id;
  548. // $compound->seksyen_kesalahan = $faulty->_id;
  549. // $compound->jumlah_asal_kompaun = $faulty->amount;
  550. // $compound->dikeluarkan = $staff->_id;
  551. // $compound->status = 'Belum Bayar';
  552. // $compound->modul = '03';
  553. // $compound->no_telefon = $request->tel;
  554. // $compound->no_akaun_lesen = $request->lesen;
  555. // $compound->created_c = Carbon::now()->toDateTimeString();
  556. // }
  557. $saved = $compound->save();
  558. }
  559. else
  560. {
  561. return $this->sendResponse('', 'Kompaun ini telah dikeluarkan!');
  562. }
  563. if($saved){
  564. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  565. // if(!empty($compound)){
  566. dispatch(new UpdateCompoundPrice($kpd));
  567. // $tawaran = '';
  568. // if($compound->jumlah_kemaskini_kompaun != ''){
  569. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  570. // }else{
  571. // $tawaran = $compound->jumlah_asal_kompaun;
  572. // }
  573. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  574. array_push($data, array('kpd' => $kpd));
  575. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  576. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  577. // }
  578. }
  579. }
  580. else{
  581. return $this->sendResponse('', 'Kompaun ini tidak dijumpai!');
  582. }
  583. }
  584. }
  585. }
  586. /**
  587. *
  588. * Store a newly created notice
  589. *
  590. **/
  591. public function storeNewNotice(Request $request)
  592. {
  593. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  594. if(empty($staff)){
  595. return $this->sendError('Invalid', 'Staff not existed');
  596. }else {
  597. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  598. if(!empty($faulty)){
  599. $data = array();
  600. $non = '';
  601. // $kpd = '';
  602. $no_siri ='';
  603. // $countKPD = $this->compound->withTrashed()->count(); //for parking numbering
  604. // do {
  605. // $kpd = $kpd + 1;
  606. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  607. // $kpd = 'KP'.$countKPD;
  608. // $no_siri = date('yn').'-'.$countKPD;
  609. // $fileData = [
  610. // 'no_siri' => $no_siri,
  611. // ];
  612. if($request->jenis == 'Parkir'){
  613. //for compound numbering
  614. // $countKPD = $this->compound->withTrashed()->count();
  615. // $kpd = 'KPD'.$countKPD;
  616. // $non = 'KPD'.$countKPD;
  617. // $no_siri = date('yn').'-'.$countKPD.'-0';
  618. // $compoundData = [
  619. // 'jenis' => 'Parkir',
  620. // 'kpd' => $kpd,
  621. // 'non' => $non,
  622. // 'nama' => '-',
  623. // 'identity' => '-',
  624. // 'alamat' => '-',
  625. // "no_plate" => strtolower($request->no_plate),
  626. // "no_cukai_jalan" => $request->noCukaijalan,
  627. // "jenis_kenderaan" => $request->jenisKenderaan,
  628. // "model_kenderaan" => $request->modelKenderaan,
  629. // "warna_kenderaan" => $request->warnakenderaan,
  630. // "nama_kawasan" => $request->namaKawasan,
  631. // "nama_taman" => $request->namaTaman,
  632. // "nama_jalan" => $request->namaJalan,
  633. // "no_parking" => $request->noParking,
  634. // "catatan" => $request->catatan,
  635. // "lokasi_kejadian" => '-',
  636. // 'latlong' => $request->Latlong,
  637. // 'jbkod' => $request->jabatan,
  638. // 'akta' => $faulty->deed_law_id,
  639. // 'seksyen_kesalahan' => $faulty->_id,
  640. // 'jumlah_asal_kompaun' => $faulty->amount,
  641. // 'jumlah_kemaskini_kompaun' => '-',
  642. // 'dikeluarkan' => $staff->_id,
  643. // "status" => 'Belum Bayar',
  644. // "amount_payment" => '-',
  645. // "receipt" => '-',
  646. // "modul" => $request->modul,
  647. // "penguatkuasa" => '-',
  648. // "notis_created" => Carbon::now()->toDateTimeString(),
  649. // ];
  650. }elseif($request->jenis == 'Notis_NKG'){
  651. // $kpd = $this->generateNumber($request->jenis, 'KT', '02');
  652. // $non = 'NKG'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  653. $non = $this->generateNumber($request->jenis, 'NKG', '02');
  654. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-1';
  655. $compoundData = [
  656. 'jenis_n' => $request->jenis,
  657. 'kpd' => '-',
  658. 'non' => $non,
  659. 'nama' => $request->namaP,
  660. 'identity' => $request->noIc,
  661. 'nama_syarikat' => $request->namaS,
  662. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  663. 'alamat' => $request->alamat,
  664. // "no_plate" => $request->no_plate,
  665. // "no_cukai_jalan" => $request->no_cukai_jalan,
  666. "nama_kawasan" => $request->namaKawasan,
  667. "nama_taman" => $request->namaTaman,
  668. "nama_jalan" => $request->namaJalan,
  669. // "catatan" => $request->catatan,
  670. // "lokasi_kejadian" => '-',
  671. 'latlong' => $request->Latlong,
  672. 'jbkod_n' => $request->jabatan,
  673. 'akta_n' => $faulty->deed_law_id,
  674. 'seksyen_kesalahan_n' => $faulty->_id,
  675. // 'jumlah_asal_kompaun' => $faulty->amount,
  676. // 'jumlah_kemaskini_kompaun' => '-',
  677. 'dikeluarkan_n' => $staff->_id,
  678. // "status" => 'Belum Bayar',
  679. // "amount_payment" => '-',
  680. // "receipt" => '-',
  681. "modul" => $request->modul,
  682. "penguatkuasa" => '-',
  683. "no_telefon" => $request->tel,
  684. "no_akaun_lesen" => $request->lesen,
  685. "maklumat_tambahan" => '-',
  686. "tindakan" => $request->tindakan,
  687. "tempoh" => $request->tempoh,
  688. "created_n" => Carbon::now()->toDateTimeString(),
  689. ];
  690. }elseif($request->jenis == 'Notis_NMH'){
  691. // $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  692. // $non = 'NMH'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  693. $non = $this->generatedNumber($request->jenis, 'NMH', '02');
  694. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-2';
  695. $compoundData = [
  696. 'jenis_n' => $request->jenis,
  697. 'kpd' => '-',
  698. 'non' => $non,
  699. 'nama' => $request->namaP,
  700. 'identity' => $request->noIc,
  701. 'nama_syarikat' => $request->namaS,
  702. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  703. 'alamat' => $request->alamat,
  704. // "no_plate" => $request->no_plate,
  705. // "no_cukai_jalan" => $request->no_cukai_jalan,
  706. "nama_kawasan" => $request->namaKawasan,
  707. "nama_taman" => $request->namaTaman,
  708. "nama_jalan" => $request->namaJalan,
  709. // "catatan" => $request->catatan,
  710. // "lokasi_kejadian" => '-',
  711. 'latlong' => $request->Latlong,
  712. 'jbkod_n' => $request->jabatan,
  713. 'akta_n' => $faulty->deed_law_id,
  714. 'seksyen_kesalahan_n' => $faulty->_id,
  715. // 'jumlah_asal_kompaun' => $faulty->amount,
  716. // 'jumlah_kemaskini_kompaun' => '-',
  717. 'dikeluarkan_n' => $staff->_id,
  718. // "status" => 'Belum Bayar',
  719. // "amount_payment" => '-',
  720. // "receipt" => '-',
  721. "modul" => $request->modul,
  722. "penguatkuasa" => '-',
  723. "no_telefon" => $request->tel,
  724. "no_akaun_lesen" => $request->lesen,
  725. "maklumat_tambahan" => '-',
  726. "tindakan" => $request->tindakan,
  727. "tempoh" => $request->tempoh,
  728. "created_n" => Carbon::now()->toDateTimeString(),
  729. ];
  730. }
  731. elseif($request->jenis == 'Notis_NHN'){
  732. //HN bcs other N stands for notice. compound number no need front N
  733. // $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  734. // $non = 'NHN'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  735. $non = $this->generateNumber($request->jenis, 'NHN', '02' );
  736. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-3';
  737. $compoundData = [
  738. 'jenis_n' => $request->jenis,
  739. 'kpd' => '-',
  740. 'non' => $non,
  741. 'nama' => $request->namaP,
  742. 'identity' => $request->noIc,
  743. 'nama_syarikat' => $request->namaS,
  744. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  745. 'alamat' => $request->alamat,
  746. // "no_plate" => $request->no_plate,
  747. // "no_cukai_jalan" => $request->no_cukai_jalan,
  748. "nama_kawasan" => $request->namaKawasan,
  749. "nama_taman" => $request->namaTaman,
  750. "nama_jalan" => $request->namaJalan,
  751. // "catatan" => $request->catatan,
  752. // "lokasi_kejadian" => '-',
  753. 'latlong' => $request->Latlong,
  754. 'jbkod_n' => $request->jabatan,
  755. 'akta_n' => $faulty->deed_law_id,
  756. 'seksyen_kesalahan_n' => $faulty->_id,
  757. // 'jumlah_asal_kompaun' => $faulty->amount,
  758. // 'jumlah_kemaskini_kompaun' => '-',
  759. 'dikeluarkan_n' => $staff->_id,
  760. // "status" => 'Belum Bayar',
  761. // "amount_payment" => '-',
  762. // "receipt" => '-',
  763. "modul" => $request->modul,
  764. "penguatkuasa" => '-',
  765. "no_telefon" => $request->tel,
  766. "no_akaun_lesen" => $request->lesen,
  767. "maklumat_tambahan" => '-',
  768. "tindakan" => $request->tindakan,
  769. "tempoh" => $request->tempoh,
  770. "created_n" => Carbon::now()->toDateTimeString(),
  771. ];
  772. }
  773. elseif($request->jenis == 'Notis_PA'){
  774. // $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  775. // $non = 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  776. $non = $this->generateNumber($request->jenis, 'PA', '02');
  777. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-4';
  778. $compoundData = [
  779. 'jenis_n' => $request->jenis,
  780. 'kpd' => '-',
  781. 'non' => $non,
  782. 'nama' => $request->namaP,
  783. 'identity' => $request->noIc,
  784. 'nama_syarikat' => $request->namaS,
  785. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  786. 'alamat' => $request->alamat,
  787. // "no_plate" => $request->no_plate,
  788. // "no_cukai_jalan" => $request->no_cukai_jalan,
  789. "nama_kawasan" => $request->namaKawasan,
  790. "nama_taman" => $request->namaTaman,
  791. "nama_jalan" => $request->namaJalan,
  792. // "catatan" => $request->catatan,
  793. // "lokasi_kejadian" => '-',
  794. 'latlong' => $request->Latlong,
  795. 'jbkod_n' => $request->jabatan,
  796. 'akta_n' => $faulty->deed_law_id,
  797. 'seksyen_kesalahan_n' => $faulty->_id,
  798. // 'jumlah_asal_kompaun' => $faulty->amount,
  799. // 'jumlah_kemaskini_kompaun' => '-',
  800. 'dikeluarkan_n' => $staff->_id,
  801. // "status" => 'Belum Bayar',
  802. // "amount_payment" => '-',
  803. // "receipt" => '-',
  804. "modul" => $request->modul,
  805. "penguatkuasa" => '-',
  806. "no_telefon" => $request->tel,
  807. "no_akaun_lesen" => $request->lesen,
  808. "maklumat_tambahan" => '-',
  809. "tindakan" => $request->tindakan,
  810. "tempoh" => $request->tempoh,
  811. "bil_haiwan" => $request->bil_haiwan,
  812. "created_n" => Carbon::now()->toDateTimeString(),
  813. ];
  814. }elseif($request->jenis == 'Notis_NPPM'){
  815. // $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  816. // $non = 'PA'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT);
  817. $non = $this->generateNumber($request->jenis, 'PA', '02');
  818. $no_siri = date('yn').'-'.filter_var($non, FILTER_SANITIZE_NUMBER_INT).'-4';
  819. $compoundData = [
  820. 'jenis_n' => $request->jenis,
  821. 'kpd' => '-',
  822. 'non' => $non,
  823. 'nama' => $request->namaP,
  824. 'identity' => $request->noIc,
  825. 'nama_syarikat' => $request->namaS,
  826. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  827. 'alamat' => $request->alamat,
  828. // "no_plate" => $request->no_plate,
  829. // "no_cukai_jalan" => $request->no_cukai_jalan,
  830. "nama_kawasan" => $request->namaKawasan,
  831. "nama_taman" => $request->namaTaman,
  832. "nama_jalan" => $request->namaJalan,
  833. // "catatan" => $request->catatan,
  834. // "lokasi_kejadian" => '-',
  835. 'latlong' => $request->Latlong,
  836. 'jbkod_n' => $request->jabatan,
  837. 'akta_n' => $faulty->deed_law_id,
  838. 'seksyen_kesalahan_n' => $faulty->_id,
  839. // 'jumlah_asal_kompaun' => $faulty->amount,
  840. // 'jumlah_kemaskini_kompaun' => '-',
  841. 'dikeluarkan_n' => $staff->_id,
  842. // "status" => 'Belum Bayar',
  843. // "amount_payment" => '-',
  844. // "receipt" => '-',
  845. "modul" => $request->modul,
  846. "penguatkuasa" => '-',
  847. "no_telefon" => $request->tel,
  848. "no_akaun_lesen" => $request->lesen,
  849. "maklumat_tambahan" => '-',
  850. "tindakan" => $request->tindakan,
  851. "tempoh" => $request->tempoh,
  852. "bil_haiwan" => $request->bil_haiwan,
  853. "created_n" => Carbon::now()->toDateTimeString(),
  854. ];
  855. }
  856. $fileData = [
  857. 'no_siri' => $no_siri,
  858. ];
  859. $file = ConfidentialFile::create($fileData);
  860. $saved = $file->compound()->create($compoundData);
  861. if($saved){
  862. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  863. // if(!empty($compound)){
  864. // dispatch(new UpdateCompoundPrice($kpd));
  865. // $tawaran = '';
  866. // if($compound->jumlah_kemaskini_kompaun != ''){
  867. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  868. // }else{
  869. // $tawaran = $compound->jumlah_asal_kompaun;
  870. // }
  871. $this->dispatch(new StoreNotice($request->all(), $non, $staff->_id, $no_siri));
  872. //mobile already accept 'kpd' string, so no need to change string name to 'notis'.
  873. array_push($data, array(
  874. 'kpd' => '-',
  875. 'non' => $non
  876. ));
  877. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  878. // }
  879. }
  880. }
  881. }
  882. }
  883. /**
  884. * Store a newly created compound (parkir, KT, JPB).
  885. *
  886. * @param \Illuminate\Http\Request $request
  887. * @return \Illuminate\Http\Response
  888. */
  889. public function storeNewCompound(Request $request)
  890. {
  891. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  892. if(empty($staff)){
  893. return $this->sendError('Invalid', 'Staff not existed');
  894. }else {
  895. $data = array();
  896. // dd($this->compound->where('jenis', 'Parkir')->withTrashed()->count());
  897. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  898. if(!empty($faulty)){
  899. $kpd = '';
  900. $no_siri ='';
  901. // $countKPD = $this->compound->withTrashed()->count();
  902. // do {
  903. // $countKPD = $countKPD + 1;
  904. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  905. // $kpd = $countKPD;
  906. // $no_siri = date('yn').'-'.$countKPD;
  907. // $fileData = [
  908. // 'no_siri' => $no_siri,
  909. // ];
  910. if($request->jenis == 'Parkir')
  911. {
  912. //for compound numbering
  913. $countKPD = $this->compound->where('jenis','Parkir')->withTrashed()->count();
  914. $kpd = 'KPD'.$countKPD;
  915. $no_siri = date('yn').'-'.$countKPD.'-0';
  916. //only for compound parkir
  917. $compoundData = [
  918. 'jenis' => 'Parkir',
  919. 'kpd' => $kpd,
  920. 'nama' => '-',
  921. 'identity' => '-',
  922. 'alamat' => '-',
  923. "no_plate" => strtolower($request->no_plate),
  924. "no_cukai_jalan" => $request->noCukaijalan,
  925. "jenis_kenderaan" => $request->jenisKenderaan,
  926. "model_kenderaan" => $request->modelKenderaan,
  927. "warna_kenderaan" => $request->warnakenderaan,
  928. "nama_kawasan" => $request->namaKawasan,
  929. "nama_taman" => $request->namaTaman,
  930. "nama_jalan" => $request->namaJalan,
  931. "no_parking" => $request->noParking,
  932. "catatan" => $request->catatan,
  933. "lokasi_kejadian" => '-',
  934. 'latlong' => $request->Latlong,
  935. 'jbkod' => $request->jabatan,
  936. 'akta' => $faulty->deed_law_id,
  937. 'seksyen_kesalahan' => $faulty->_id,
  938. 'jumlah_asal_kompaun' => $faulty->amount,
  939. 'jumlah_kemaskini_kompaun' => '-',
  940. 'dikeluarkan' => $staff->_id,
  941. "status" => 'Belum Bayar',
  942. "amount_payment" => '-',
  943. "receipt" => '-',
  944. "modul" => '03',
  945. "penguatkuasa" => '-',
  946. "created_c" => Carbon::now()->toDateTimeString(),
  947. ];
  948. }
  949. if ($request->jenis == 'Pelbagai_KT') {
  950. $kpd = $this->generateNumber($request->jenis, 'KT', '03');
  951. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  952. $compoundData = [
  953. 'jenis' => $request->jenis,
  954. 'kpd' => $kpd,
  955. 'nama' => $request->namaP,
  956. 'identity' => $request->noIc,
  957. 'nama_syarikat' => $request->namaS,
  958. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  959. 'alamat' => $request->alamat,
  960. // "no_plate" => $request->no_plate,
  961. // "no_cukai_jalan" => $request->no_cukai_jalan,
  962. "nama_kawasan" => $request->namaKawasan,
  963. "nama_taman" => $request->namaTaman,
  964. "nama_jalan" => $request->namaJalan,
  965. "catatan" => $request->catatan,
  966. // "lokasi_kejadian" => '-',
  967. 'latlong' => $request->Latlong,
  968. 'jbkod' => $request->jabatan,
  969. 'akta' => $faulty->deed_law_id,
  970. 'seksyen_kesalahan' => $faulty->_id,
  971. 'jumlah_asal_kompaun' => $faulty->amount,
  972. 'jumlah_kemaskini_kompaun' => '-',
  973. 'dikeluarkan' => $staff->_id,
  974. "status" => 'Belum Bayar',
  975. "amount_payment" => '-',
  976. "receipt" => '-',
  977. "modul" => $request->modul,
  978. "penguatkuasa" => '-',
  979. "no_telefon" => $request->tel,
  980. "no_akaun_lesen" => $request->lesen,
  981. "maklumat_tambahan" => '-',
  982. "tindakan" => '-',
  983. "tempoh" => '-',
  984. "created_c" => Carbon::now()->toDateTimeString(),
  985. ];
  986. }
  987. elseif ($request->jenis == 'Pelbagai_JPB') {
  988. $kpd = $this->generateNumber($request->jenis, 'JPB', '03');
  989. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  990. $compoundData = [
  991. 'jenis' => $request->jenis,
  992. 'kpd' => $kpd,
  993. 'nama' => $request->namaP,
  994. 'identity' => $request->noIc,
  995. 'nama_syarikat' => $request->namaS,
  996. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  997. 'alamat' => $request->alamat,
  998. // "no_plate" => $request->no_plate,
  999. // "no_cukai_jalan" => $request->no_cukai_jalan,
  1000. "nama_kawasan" => $request->namaKawasan,
  1001. "nama_taman" => $request->namaTaman,
  1002. "nama_jalan" => $request->namaJalan,
  1003. "catatan" => $request->catatan,
  1004. // "lokasi_kejadian" => '-',
  1005. 'latlong' => $request->Latlong,
  1006. 'jbkod' => $request->jabatan,
  1007. 'akta' => $faulty->deed_law_id,
  1008. 'seksyen_kesalahan' => $faulty->_id,
  1009. 'jumlah_asal_kompaun' => $faulty->amount,
  1010. 'jumlah_kemaskini_kompaun' => '-',
  1011. 'dikeluarkan' => $staff->_id,
  1012. "status" => 'Belum Bayar',
  1013. "amount_payment" => '-',
  1014. "receipt" => '-',
  1015. "modul" => $request->modul,
  1016. "penguatkuasa" => '-',
  1017. "no_telefon" => $request->tel,
  1018. "no_akaun_lesen" => $request->lesen,
  1019. "maklumat_tambahan" => '-',
  1020. "tindakan" => '-',
  1021. "tempoh" => '-',
  1022. "created_c" => Carbon::now()->toDateTimeString(),
  1023. ];
  1024. }
  1025. // elseif ($request->jenis == 'Pelbagai_LESEN') {
  1026. // //HN bcs other N stands for notice. compound number no need front N
  1027. // $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  1028. // $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-3';
  1029. // $compoundData = [
  1030. // 'jenis' => $request->jenis,
  1031. // 'kpd' => $kpd,
  1032. // 'nama' => $request->namaP,
  1033. // 'identity' => $request->noIc,
  1034. // 'nama_syarikat' => $request->namaS,
  1035. // 'no_daftar_syarikat' => strtolower($request->daftarNo),
  1036. // 'alamat' => $request->alamat,
  1037. // "no_plate" => $request->no_plate,
  1038. // "no_cukai_jalan" => $request->no_cukai_jalan,
  1039. // "nama_kawasan" => $request->namaKawasan,
  1040. // "nama_taman" => $request->namaTaman,
  1041. // "nama_jalan" => $request->namaJalan,
  1042. // "catatan" => $request->catatan,
  1043. // "lokasi_kejadian" => '-',
  1044. // 'latlong' => $request->Latlong,
  1045. // 'jbkod' => $request->jabatan,
  1046. // 'akta' => $faulty->deed_law_id,
  1047. // 'seksyen_kesalahan' => $faulty->_id,
  1048. // 'jumlah_asal_kompaun' => $faulty->amount,
  1049. // 'jumlah_kemaskini_kompaun' => '-',
  1050. // 'dikeluarkan' => $staff->_id,
  1051. // "status" => 'Belum Bayar',
  1052. // "amount_payment" => '-',
  1053. // "receipt" => '-',
  1054. // "modul" => $request->modul,
  1055. // "penguatkuasa" => '-',
  1056. // "no_telefon" => $request->tel,
  1057. // "no_akaun_lesen" => $request->lesen,
  1058. // "maklumat_tambahan" => '-',
  1059. // "created_c" => Carbon::now()->toDateTimeString(),
  1060. // ];
  1061. // }
  1062. // else if($request->jenis == 'Pelbagai_PA'){
  1063. // $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  1064. // $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-4';
  1065. // $compoundData = [
  1066. // 'jenis' => $request->jenis,
  1067. // 'kpd' => $kpd,
  1068. // 'nama' => $request->namaP,
  1069. // 'identity' => $request->noIc,
  1070. // 'nama_syarikat' => $request->namaS,
  1071. // 'no_daftar_syarikat' => strtolower($request->daftarNo),
  1072. // 'alamat' => $request->alamat,
  1073. // "no_plate" => $request->no_plate,
  1074. // "no_cukai_jalan" => $request->no_cukai_jalan,
  1075. // "nama_kawasan" => $request->namaKawasan,
  1076. // "nama_taman" => $request->namaTaman,
  1077. // "nama_jalan" => $request->namaJalan,
  1078. // "catatan" => $request->catatan,
  1079. // "lokasi_kejadian" => '-',
  1080. // 'latlong' => $request->Latlong,
  1081. // 'jbkod' => $request->jabatan,
  1082. // 'akta' => $faulty->deed_law_id,
  1083. // 'seksyen_kesalahan' => $faulty->_id,
  1084. // 'jumlah_asal_kompaun' => $faulty->amount,
  1085. // 'jumlah_kemaskini_kompaun' => '-',
  1086. // 'dikeluarkan' => $staff->_id,
  1087. // "status" => 'Belum Bayar',
  1088. // "amount_payment" => '-',
  1089. // "receipt" => '-',
  1090. // "modul" => $request->modul,
  1091. // "penguatkuasa" => '-',
  1092. // "no_telefon" => $request->tel,
  1093. // "no_akaun_lesen" => $request->lesen,
  1094. // "maklumat_tambahan" => '-',
  1095. // "bil_haiwan" => $request->bil_haiwan,
  1096. // "cpn_created" => Carbon::now()->toDateTimeString(),
  1097. // ];
  1098. // }
  1099. $fileData = [
  1100. 'no_siri' => $no_siri,
  1101. ];
  1102. $file = ConfidentialFile::create($fileData);
  1103. $saved = $file->compound()->create($compoundData);
  1104. if($saved){
  1105. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  1106. // if(!empty($compound)){
  1107. dispatch(new UpdateCompoundPrice($kpd));
  1108. // $tawaran = '';
  1109. // if($compound->jumlah_kemaskini_kompaun != ''){
  1110. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  1111. // }else{
  1112. // $tawaran = $compound->jumlah_asal_kompaun;
  1113. // }
  1114. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  1115. array_push($data, array('kpd' => $kpd));
  1116. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  1117. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  1118. }
  1119. return $this->sendError('', 'Tidak berjaya simpan rekod kompaun!');
  1120. }
  1121. return $this->sendResponse('Tidak Berjaya!', 'Kesalahan tidak dijumpai!');
  1122. }
  1123. }
  1124. /**
  1125. * Display the specified resource.
  1126. *
  1127. * @param int $id
  1128. * @return \Illuminate\Http\Response
  1129. */
  1130. public function show($id)
  1131. {
  1132. //
  1133. }
  1134. /**
  1135. * Show the form for editing the specified resource.
  1136. *
  1137. * @param int $id
  1138. * @return \Illuminate\Http\Response
  1139. */
  1140. public function edit($id)
  1141. {
  1142. //
  1143. }
  1144. /**
  1145. * Update the specified resource in storage.
  1146. *
  1147. * @param \Illuminate\Http\Request $request
  1148. * @param int $id
  1149. * @return \Illuminate\Http\Response
  1150. */
  1151. public function update(Request $request, $id)
  1152. {
  1153. //
  1154. }
  1155. public function updateStatusNoticeViaDashboard(Request $request)
  1156. {
  1157. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1158. $staff = StaffDetail::find($request->current_id);
  1159. if(!empty($compound) && !empty($staff)){
  1160. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1161. if($compound->status != $request->status){
  1162. $compound->status = $request->status;
  1163. $compound->catatan_dari_admin = $request->remark;
  1164. $compound->update_by = $request->current_id;
  1165. $saved = $compound->save();
  1166. if($saved){
  1167. $gDate = $compound->created_at->format('F Y');
  1168. $historyData = [
  1169. 'tarikh_kumpulan' => $gDate,
  1170. ];
  1171. $subHistory = [
  1172. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1173. 'tajuk' => "Status notis ".$compound->kpd. " telah dikemaskini",
  1174. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1175. ];
  1176. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1177. if(!empty($groupByDate)){
  1178. $groupByDate->subhistory()->create($subHistory);
  1179. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1180. }else{
  1181. $history = History::create($historyData);
  1182. $history->subhistory()->create($subHistory);
  1183. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1184. }
  1185. if($request->status == "Berbayar"){
  1186. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1187. }else{
  1188. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1189. }
  1190. }else{
  1191. $response = [
  1192. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1193. ];
  1194. return response()->json($response, 200);
  1195. }
  1196. }else{
  1197. if($request->remark != ''){
  1198. $compound->catatan_dari_admin = $request->remark;
  1199. $compound->update_by = $request->current_id;
  1200. $compound->save();
  1201. $saved = $compound->save();
  1202. if($saved){
  1203. $gDate = $compound->created_at->format('F Y');
  1204. $historyData = [
  1205. 'tarikh_kumpulan' => $gDate,
  1206. ];
  1207. $subHistory = [
  1208. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1209. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1210. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1211. ];
  1212. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1213. if(!empty($groupByDate)){
  1214. $groupByDate->subhistory()->create($subHistory);
  1215. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1216. }else{
  1217. $history = History::create($historyData);
  1218. $history->subhistory()->create($subHistory);
  1219. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1220. }
  1221. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1222. }else{
  1223. $response = [
  1224. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1225. ];
  1226. return response()->json($response, 200);
  1227. }
  1228. }else{
  1229. $response = [
  1230. 'success' => false, 'message' => 'Tiada kemaskini!',
  1231. ];
  1232. return response()->json($response, 200);
  1233. }
  1234. }
  1235. }else{
  1236. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1237. $compound->status = $request->status;
  1238. $compound->catatan_dari_admin = $request->remark;
  1239. // $compound->amount_payment = $request->amount;
  1240. $compound->update_by = $request->current_id;
  1241. $saved = $compound->save();
  1242. if($saved){
  1243. $gDate = $compound->created_at->format('F Y');
  1244. $historyData = [
  1245. 'tarikh_kumpulan' => $gDate,
  1246. ];
  1247. $subHistory = [
  1248. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1249. 'tajuk' => "Status notis telah dikemaskini",
  1250. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1251. ];
  1252. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1253. if(!empty($groupByDate)){
  1254. $groupByDate->subhistory()->create($subHistory);
  1255. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1256. }else{
  1257. $history = History::create($historyData);
  1258. $history->subhistory()->create($subHistory);
  1259. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1260. }
  1261. if($request->status == "Berbayar"){
  1262. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1263. }else{
  1264. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1265. }
  1266. }else{
  1267. $response = [
  1268. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1269. ];
  1270. return response()->json($response, 200);
  1271. }
  1272. }else{
  1273. if($request->remark != ''){
  1274. $compound->catatan_dari_admin = $request->remark;
  1275. $compound->update_by = $request->current_id;
  1276. $compound->save();
  1277. $saved = $compound->save();
  1278. if($saved){
  1279. $gDate = $compound->created_at->format('F Y');
  1280. $historyData = [
  1281. 'tarikh_kumpulan' => $gDate,
  1282. ];
  1283. $subHistory = [
  1284. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1285. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1286. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1287. ];
  1288. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1289. if(!empty($groupByDate)){
  1290. $groupByDate->subhistory()->create($subHistory);
  1291. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1292. }else{
  1293. $history = History::create($historyData);
  1294. $history->subhistory()->create($subHistory);
  1295. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1296. }
  1297. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1298. }else{
  1299. $response = [
  1300. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1301. ];
  1302. return response()->json($response, 200);
  1303. }
  1304. }else{
  1305. $response = [
  1306. 'success' => false, 'message' => 'Tiada kemaskini!',
  1307. ];
  1308. return response()->json($response, 200);
  1309. }
  1310. }
  1311. }
  1312. }else{
  1313. $response = [
  1314. 'success' => false,
  1315. 'message' => 'Notis ini tidak dijumpai / staff tidak ditemui',
  1316. ];
  1317. return response()->json($response, 200);
  1318. }
  1319. }
  1320. public function updateStatusPaymentViaDashboard(Request $request)
  1321. {
  1322. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1323. $staff = StaffDetail::find($request->current_id);
  1324. if(!empty($compound) && !empty($staff)){
  1325. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1326. if($compound->status != $request->status){
  1327. $compound->status = $request->status;
  1328. $compound->catatan_dari_admin = $request->remark;
  1329. $compound->amount_payment = $request->amount;
  1330. $compound->update_by = $request->current_id;
  1331. $saved = $compound->save();
  1332. if($saved){
  1333. $gDate = $compound->created_at->format('F Y');
  1334. $historyData = [
  1335. 'tarikh_kumpulan' => $gDate,
  1336. ];
  1337. $subHistory = [
  1338. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1339. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1340. '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>",
  1341. ];
  1342. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1343. if(!empty($groupByDate)){
  1344. $groupByDate->subhistory()->create($subHistory);
  1345. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1346. }else{
  1347. $history = History::create($historyData);
  1348. $history->subhistory()->create($subHistory);
  1349. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1350. }
  1351. if($request->status == "Berbayar"){
  1352. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1353. }else{
  1354. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1355. }
  1356. }else{
  1357. $response = [
  1358. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1359. ];
  1360. return response()->json($response, 200);
  1361. }
  1362. }else{
  1363. if($request->remark != ''){
  1364. $compound->catatan_dari_admin = $request->remark;
  1365. $compound->update_by = $request->current_id;
  1366. $compound->save();
  1367. $saved = $compound->save();
  1368. if($saved){
  1369. $gDate = $compound->created_at->format('F Y');
  1370. $historyData = [
  1371. 'tarikh_kumpulan' => $gDate,
  1372. ];
  1373. $subHistory = [
  1374. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1375. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1376. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1377. ];
  1378. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1379. if(!empty($groupByDate)){
  1380. $groupByDate->subhistory()->create($subHistory);
  1381. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1382. }else{
  1383. $history = History::create($historyData);
  1384. $history->subhistory()->create($subHistory);
  1385. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1386. }
  1387. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1388. }else{
  1389. $response = [
  1390. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1391. ];
  1392. return response()->json($response, 200);
  1393. }
  1394. }else{
  1395. $response = [
  1396. 'success' => false, 'message' => 'Tiada kemaskini!',
  1397. ];
  1398. return response()->json($response, 200);
  1399. }
  1400. }
  1401. }else{
  1402. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1403. $compound->status = $request->status;
  1404. $compound->catatan_dari_admin = $request->remark;
  1405. $compound->amount_payment = $request->amount;
  1406. $compound->update_by = $request->current_id;
  1407. $saved = $compound->save();
  1408. if($saved){
  1409. $gDate = $compound->created_at->format('F Y');
  1410. $historyData = [
  1411. 'tarikh_kumpulan' => $gDate,
  1412. ];
  1413. $subHistory = [
  1414. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1415. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1416. '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>",
  1417. ];
  1418. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1419. if(!empty($groupByDate)){
  1420. $groupByDate->subhistory()->create($subHistory);
  1421. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1422. }else{
  1423. $history = History::create($historyData);
  1424. $history->subhistory()->create($subHistory);
  1425. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1426. }
  1427. if($request->status == "Berbayar"){
  1428. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1429. }else{
  1430. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1431. }
  1432. }else{
  1433. $response = [
  1434. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1435. ];
  1436. return response()->json($response, 200);
  1437. }
  1438. }else{
  1439. if($request->remark != ''){
  1440. $compound->catatan_dari_admin = $request->remark;
  1441. $compound->update_by = $request->current_id;
  1442. $compound->save();
  1443. $saved = $compound->save();
  1444. if($saved){
  1445. $gDate = $compound->created_at->format('F Y');
  1446. $historyData = [
  1447. 'tarikh_kumpulan' => $gDate,
  1448. ];
  1449. $subHistory = [
  1450. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1451. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1452. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1453. ];
  1454. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1455. if(!empty($groupByDate)){
  1456. $groupByDate->subhistory()->create($subHistory);
  1457. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1458. }else{
  1459. $history = History::create($historyData);
  1460. $history->subhistory()->create($subHistory);
  1461. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1462. }
  1463. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1464. }else{
  1465. $response = [
  1466. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1467. ];
  1468. return response()->json($response, 200);
  1469. }
  1470. }else{
  1471. $response = [
  1472. 'success' => false, 'message' => 'Tiada kemaskini!',
  1473. ];
  1474. return response()->json($response, 200);
  1475. }
  1476. }
  1477. }
  1478. }else{
  1479. $response = [
  1480. 'success' => false,
  1481. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  1482. ];
  1483. return response()->json($response, 200);
  1484. }
  1485. }
  1486. /**
  1487. * Remove the specified resource from storage.
  1488. *
  1489. * @param int $id
  1490. * @return \Illuminate\Http\Response
  1491. */
  1492. public function destroy($id)
  1493. {
  1494. //
  1495. }
  1496. }