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

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