Dashboard sipadu mbip
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

CompoundResourceController.php 73KB

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