Dashboard sipadu mbip
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

CompoundResourceController.php 73KB

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