Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompoundResourceController.php 74KB

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