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

CompoundResourceController.php 70KB

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