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 69KB

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