Dashboard sipadu mbip
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CompoundResourceController.php 74KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  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'))->orWhere(strtolower('nama'), strtolower($request->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(
  795. 'kpd' => $kpd,
  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. // $countKPD = $this->compound->withTrashed()->count();
  822. // do {
  823. // $countKPD = $countKPD + 1;
  824. // } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  825. // $kpd = $countKPD;
  826. // $no_siri = date('yn').'-'.$countKPD;
  827. // $fileData = [
  828. // 'no_siri' => $no_siri,
  829. // ];
  830. if($request->jenis == 'Parkir')
  831. {
  832. //for compound numbering
  833. $countKPD = $this->compound->withTrashed()->count();
  834. $kpd = 'KPD'.$countKPD;
  835. $no_siri = date('yn').'-'.$countKPD.'-0';
  836. //only for compound parkir
  837. $compoundData = [
  838. 'jenis' => 'Parkir',
  839. 'kpd' => $kpd,
  840. 'nama' => '-',
  841. 'identity' => '-',
  842. 'alamat' => '-',
  843. "no_plate" => strtolower($request->no_plate),
  844. "no_cukai_jalan" => $request->noCukaijalan,
  845. "jenis_kenderaan" => $request->jenisKenderaan,
  846. "model_kenderaan" => $request->modelKenderaan,
  847. "warna_kenderaan" => $request->warnakenderaan,
  848. "nama_kawasan" => $request->namaKawasan,
  849. "nama_taman" => $request->namaTaman,
  850. "nama_jalan" => $request->namaJalan,
  851. "no_parking" => $request->noParking,
  852. "catatan" => $request->catatan,
  853. "lokasi_kejadian" => '-',
  854. 'latlong' => $request->Latlong,
  855. 'jbkod' => $request->jabatan,
  856. 'akta' => $faulty->deed_law_id,
  857. 'seksyen_kesalahan' => $faulty->_id,
  858. 'jumlah_asal_kompaun' => $faulty->amount,
  859. 'jumlah_kemaskini_kompaun' => '-',
  860. 'dikeluarkan' => $staff->_id,
  861. "status" => 'Belum Bayar',
  862. "amount_payment" => '-',
  863. "receipt" => '-',
  864. "modul" => '03',
  865. "penguatkuasa" => '-',
  866. "cpn_created" => Carbon::now()->toDateTimeString(),
  867. ];
  868. }
  869. if ($request->jenis == 'Pelbagai_KT') {
  870. $kpd = $this->generateCompoundNumber($request->jenis, 'KT');
  871. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-1';
  872. $compoundData = [
  873. 'jenis' => $request->jenis,
  874. 'kpd' => $kpd,
  875. 'nama' => $request->namaP,
  876. 'identity' => $request->noIc,
  877. 'nama_syarikat' => $request->namaS,
  878. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  879. 'alamat' => $request->alamat,
  880. "no_plate" => $request->no_plate,
  881. "no_cukai_jalan" => $request->no_cukai_jalan,
  882. "nama_kawasan" => $request->namaKawasan,
  883. "nama_taman" => $request->namaTaman,
  884. "nama_jalan" => $request->namaJalan,
  885. "catatan" => $request->catatan,
  886. "lokasi_kejadian" => '-',
  887. 'latlong' => $request->Latlong,
  888. 'jbkod' => $request->jabatan,
  889. 'akta' => $faulty->deed_law_id,
  890. 'seksyen_kesalahan' => $faulty->_id,
  891. 'jumlah_asal_kompaun' => $faulty->amount,
  892. 'jumlah_kemaskini_kompaun' => '-',
  893. 'dikeluarkan' => $staff->_id,
  894. "status" => 'Belum Bayar',
  895. "amount_payment" => '-',
  896. "receipt" => '-',
  897. "modul" => $request->modul,
  898. "penguatkuasa" => '-',
  899. "no_telefon" => $request->tel,
  900. "no_akaun_lesen" => $request->lesen,
  901. "maklumat_tambahan" => '-',
  902. "tindakan" => '-',
  903. "tempoh" => '-',
  904. "cpn_created" => Carbon::now()->toDateTimeString(),
  905. ];
  906. }
  907. elseif ($request->jenis == 'Pelbagai_JPB') {
  908. $kpd = $this->generateCompoundNumber($request->jenis, 'JPB');
  909. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-2';
  910. $compoundData = [
  911. 'jenis' => $request->jenis,
  912. 'kpd' => $kpd,
  913. 'nama' => $request->namaP,
  914. 'identity' => $request->noIc,
  915. 'nama_syarikat' => $request->namaS,
  916. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  917. 'alamat' => $request->alamat,
  918. "no_plate" => $request->no_plate,
  919. "no_cukai_jalan" => $request->no_cukai_jalan,
  920. "nama_kawasan" => $request->namaKawasan,
  921. "nama_taman" => $request->namaTaman,
  922. "nama_jalan" => $request->namaJalan,
  923. "catatan" => $request->catatan,
  924. "lokasi_kejadian" => '-',
  925. 'latlong' => $request->Latlong,
  926. 'jbkod' => $request->jabatan,
  927. 'akta' => $faulty->deed_law_id,
  928. 'seksyen_kesalahan' => $faulty->_id,
  929. 'jumlah_asal_kompaun' => $faulty->amount,
  930. 'jumlah_kemaskini_kompaun' => '-',
  931. 'dikeluarkan' => $staff->_id,
  932. "status" => 'Belum Bayar',
  933. "amount_payment" => '-',
  934. "receipt" => '-',
  935. "modul" => $request->modul,
  936. "penguatkuasa" => '-',
  937. "no_telefon" => $request->tel,
  938. "no_akaun_lesen" => $request->lesen,
  939. "maklumat_tambahan" => '-',
  940. "tindakan" => '-',
  941. "tempoh" => '-',
  942. "cpn_created" => Carbon::now()->toDateTimeString(),
  943. ];
  944. }
  945. elseif ($request->jenis == 'Pelbagai_LESEN') {
  946. //HN bcs other N stands for notice. compound number no need front N
  947. $kpd = $this->generateCompoundNumber($request->jenis, 'HN');
  948. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-3';
  949. $compoundData = [
  950. 'jenis' => $request->jenis,
  951. 'kpd' => $kpd,
  952. 'nama' => $request->namaP,
  953. 'identity' => $request->noIc,
  954. 'nama_syarikat' => $request->namaS,
  955. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  956. 'alamat' => $request->alamat,
  957. "no_plate" => $request->no_plate,
  958. "no_cukai_jalan" => $request->no_cukai_jalan,
  959. "nama_kawasan" => $request->namaKawasan,
  960. "nama_taman" => $request->namaTaman,
  961. "nama_jalan" => $request->namaJalan,
  962. "catatan" => $request->catatan,
  963. "lokasi_kejadian" => '-',
  964. 'latlong' => $request->Latlong,
  965. 'jbkod' => $request->jabatan,
  966. 'akta' => $faulty->deed_law_id,
  967. 'seksyen_kesalahan' => $faulty->_id,
  968. 'jumlah_asal_kompaun' => $faulty->amount,
  969. 'jumlah_kemaskini_kompaun' => '-',
  970. 'dikeluarkan' => $staff->_id,
  971. "status" => 'Belum Bayar',
  972. "amount_payment" => '-',
  973. "receipt" => '-',
  974. "modul" => $request->modul,
  975. "penguatkuasa" => '-',
  976. "no_telefon" => $request->tel,
  977. "no_akaun_lesen" => $request->lesen,
  978. "maklumat_tambahan" => '-',
  979. "cpn_created" => Carbon::now()->toDateTimeString(),
  980. ];
  981. }
  982. else if($request->jenis == 'Pelbagai_PA'){
  983. $kpd = $this->generateCompoundNumber($request->jenis, 'PA');
  984. $no_siri = date('yn').'-'.filter_var($kpd, FILTER_SANITIZE_NUMBER_INT).'-4';
  985. $compoundData = [
  986. 'jenis' => $request->jenis,
  987. 'kpd' => $kpd,
  988. 'nama' => $request->namaP,
  989. 'identity' => $request->noIc,
  990. 'nama_syarikat' => $request->namaS,
  991. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  992. 'alamat' => $request->alamat,
  993. "no_plate" => $request->no_plate,
  994. "no_cukai_jalan" => $request->no_cukai_jalan,
  995. "nama_kawasan" => $request->namaKawasan,
  996. "nama_taman" => $request->namaTaman,
  997. "nama_jalan" => $request->namaJalan,
  998. "catatan" => $request->catatan,
  999. "lokasi_kejadian" => '-',
  1000. 'latlong' => $request->Latlong,
  1001. 'jbkod' => $request->jabatan,
  1002. 'akta' => $faulty->deed_law_id,
  1003. 'seksyen_kesalahan' => $faulty->_id,
  1004. 'jumlah_asal_kompaun' => $faulty->amount,
  1005. 'jumlah_kemaskini_kompaun' => '-',
  1006. 'dikeluarkan' => $staff->_id,
  1007. "status" => 'Belum Bayar',
  1008. "amount_payment" => '-',
  1009. "receipt" => '-',
  1010. "modul" => $request->modul,
  1011. "penguatkuasa" => '-',
  1012. "no_telefon" => $request->tel,
  1013. "no_akaun_lesen" => $request->lesen,
  1014. "maklumat_tambahan" => '-',
  1015. "bil_haiwan" => $request->bil_haiwan,
  1016. "cpn_created" => Carbon::now()->toDateTimeString(),
  1017. ];
  1018. }
  1019. $fileData = [
  1020. 'no_siri' => $no_siri,
  1021. ];
  1022. $file = ConfidentialFile::create($fileData);
  1023. $saved = $file->compound()->create($compoundData);
  1024. if($saved){
  1025. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  1026. // if(!empty($compound)){
  1027. dispatch(new UpdateCompoundPrice($kpd));
  1028. // $tawaran = '';
  1029. // if($compound->jumlah_kemaskini_kompaun != ''){
  1030. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  1031. // }else{
  1032. // $tawaran = $compound->jumlah_asal_kompaun;
  1033. // }
  1034. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  1035. array_push($data, array('kpd' => $kpd));
  1036. $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  1037. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  1038. }
  1039. return $this->sendError('', 'Tidak berjaya simpan rekod kompaun!');
  1040. }
  1041. return $this->sendResponse('Tidak Berjaya!', 'Kesalahan tidak dijumpai!');
  1042. }
  1043. }
  1044. /**
  1045. * Display the specified resource.
  1046. *
  1047. * @param int $id
  1048. * @return \Illuminate\Http\Response
  1049. */
  1050. public function show($id)
  1051. {
  1052. //
  1053. }
  1054. /**
  1055. * Show the form for editing the specified resource.
  1056. *
  1057. * @param int $id
  1058. * @return \Illuminate\Http\Response
  1059. */
  1060. public function edit($id)
  1061. {
  1062. //
  1063. }
  1064. /**
  1065. * Update the specified resource in storage.
  1066. *
  1067. * @param \Illuminate\Http\Request $request
  1068. * @param int $id
  1069. * @return \Illuminate\Http\Response
  1070. */
  1071. public function update(Request $request, $id)
  1072. {
  1073. //
  1074. }
  1075. public function updateStatusNoticeViaDashboard(Request $request)
  1076. {
  1077. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1078. $staff = StaffDetail::find($request->current_id);
  1079. if(!empty($compound) && !empty($staff)){
  1080. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1081. if($compound->status != $request->status){
  1082. $compound->status = $request->status;
  1083. $compound->catatan_dari_admin = $request->remark;
  1084. $compound->update_by = $request->current_id;
  1085. $saved = $compound->save();
  1086. if($saved){
  1087. $gDate = $compound->created_at->format('F Y');
  1088. $historyData = [
  1089. 'tarikh_kumpulan' => $gDate,
  1090. ];
  1091. $subHistory = [
  1092. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1093. 'tajuk' => "Status notis ".$compound->kpd. " telah dikemaskini",
  1094. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1095. ];
  1096. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1097. if(!empty($groupByDate)){
  1098. $groupByDate->subhistory()->create($subHistory);
  1099. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1100. }else{
  1101. $history = History::create($historyData);
  1102. $history->subhistory()->create($subHistory);
  1103. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1104. }
  1105. if($request->status == "Berbayar"){
  1106. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1107. }else{
  1108. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1109. }
  1110. }else{
  1111. $response = [
  1112. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1113. ];
  1114. return response()->json($response, 200);
  1115. }
  1116. }else{
  1117. if($request->remark != ''){
  1118. $compound->catatan_dari_admin = $request->remark;
  1119. $compound->update_by = $request->current_id;
  1120. $compound->save();
  1121. $saved = $compound->save();
  1122. if($saved){
  1123. $gDate = $compound->created_at->format('F Y');
  1124. $historyData = [
  1125. 'tarikh_kumpulan' => $gDate,
  1126. ];
  1127. $subHistory = [
  1128. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1129. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1130. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1131. ];
  1132. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1133. if(!empty($groupByDate)){
  1134. $groupByDate->subhistory()->create($subHistory);
  1135. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1136. }else{
  1137. $history = History::create($historyData);
  1138. $history->subhistory()->create($subHistory);
  1139. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1140. }
  1141. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1142. }else{
  1143. $response = [
  1144. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1145. ];
  1146. return response()->json($response, 200);
  1147. }
  1148. }else{
  1149. $response = [
  1150. 'success' => false, 'message' => 'Tiada kemaskini!',
  1151. ];
  1152. return response()->json($response, 200);
  1153. }
  1154. }
  1155. }else{
  1156. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1157. $compound->status = $request->status;
  1158. $compound->catatan_dari_admin = $request->remark;
  1159. // $compound->amount_payment = $request->amount;
  1160. $compound->update_by = $request->current_id;
  1161. $saved = $compound->save();
  1162. if($saved){
  1163. $gDate = $compound->created_at->format('F Y');
  1164. $historyData = [
  1165. 'tarikh_kumpulan' => $gDate,
  1166. ];
  1167. $subHistory = [
  1168. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1169. 'tajuk' => "Status notis telah dikemaskini",
  1170. 'huraian' => "Status penyelesaian notis telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1171. ];
  1172. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1173. if(!empty($groupByDate)){
  1174. $groupByDate->subhistory()->create($subHistory);
  1175. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1176. }else{
  1177. $history = History::create($historyData);
  1178. $history->subhistory()->create($subHistory);
  1179. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1180. }
  1181. if($request->status == "Berbayar"){
  1182. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis Dijelaskan" ');
  1183. }else{
  1184. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk notis ini di modul kategori "Kompaun/Notis DiBatalkan" ');
  1185. }
  1186. }else{
  1187. $response = [
  1188. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1189. ];
  1190. return response()->json($response, 200);
  1191. }
  1192. }else{
  1193. if($request->remark != ''){
  1194. $compound->catatan_dari_admin = $request->remark;
  1195. $compound->update_by = $request->current_id;
  1196. $compound->save();
  1197. $saved = $compound->save();
  1198. if($saved){
  1199. $gDate = $compound->created_at->format('F Y');
  1200. $historyData = [
  1201. 'tarikh_kumpulan' => $gDate,
  1202. ];
  1203. $subHistory = [
  1204. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1205. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1206. 'huraian' => "Catatan notis ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1207. ];
  1208. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1209. if(!empty($groupByDate)){
  1210. $groupByDate->subhistory()->create($subHistory);
  1211. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1212. }else{
  1213. $history = History::create($historyData);
  1214. $history->subhistory()->create($subHistory);
  1215. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1216. }
  1217. return $this->sendResponse('', 'Berjaya tambah catatan untuk notis ini');
  1218. }else{
  1219. $response = [
  1220. 'success' => false, 'message' => 'Notis ini tidak berjaya dikemaskini',
  1221. ];
  1222. return response()->json($response, 200);
  1223. }
  1224. }else{
  1225. $response = [
  1226. 'success' => false, 'message' => 'Tiada kemaskini!',
  1227. ];
  1228. return response()->json($response, 200);
  1229. }
  1230. }
  1231. }
  1232. }else{
  1233. $response = [
  1234. 'success' => false,
  1235. 'message' => 'Notis ini tidak dijumpai / staff tidak ditemui',
  1236. ];
  1237. return response()->json($response, 200);
  1238. }
  1239. }
  1240. public function updateStatusPaymentViaDashboard(Request $request)
  1241. {
  1242. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1243. $staff = StaffDetail::find($request->current_id);
  1244. if(!empty($compound) && !empty($staff)){
  1245. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1246. if($compound->status != $request->status){
  1247. $compound->status = $request->status;
  1248. $compound->catatan_dari_admin = $request->remark;
  1249. $compound->amount_payment = $request->amount;
  1250. $compound->update_by = $request->current_id;
  1251. $saved = $compound->save();
  1252. if($saved){
  1253. $gDate = $compound->created_at->format('F Y');
  1254. $historyData = [
  1255. 'tarikh_kumpulan' => $gDate,
  1256. ];
  1257. $subHistory = [
  1258. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1259. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1260. '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>",
  1261. ];
  1262. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1263. if(!empty($groupByDate)){
  1264. $groupByDate->subhistory()->create($subHistory);
  1265. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1266. }else{
  1267. $history = History::create($historyData);
  1268. $history->subhistory()->create($subHistory);
  1269. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1270. }
  1271. if($request->status == "Berbayar"){
  1272. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1273. }else{
  1274. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1275. }
  1276. }else{
  1277. $response = [
  1278. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1279. ];
  1280. return response()->json($response, 200);
  1281. }
  1282. }else{
  1283. if($request->remark != ''){
  1284. $compound->catatan_dari_admin = $request->remark;
  1285. $compound->update_by = $request->current_id;
  1286. $compound->save();
  1287. $saved = $compound->save();
  1288. if($saved){
  1289. $gDate = $compound->created_at->format('F Y');
  1290. $historyData = [
  1291. 'tarikh_kumpulan' => $gDate,
  1292. ];
  1293. $subHistory = [
  1294. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1295. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1296. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1297. ];
  1298. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1299. if(!empty($groupByDate)){
  1300. $groupByDate->subhistory()->create($subHistory);
  1301. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1302. }else{
  1303. $history = History::create($historyData);
  1304. $history->subhistory()->create($subHistory);
  1305. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1306. }
  1307. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1308. }else{
  1309. $response = [
  1310. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1311. ];
  1312. return response()->json($response, 200);
  1313. }
  1314. }else{
  1315. $response = [
  1316. 'success' => false, 'message' => 'Tiada kemaskini!',
  1317. ];
  1318. return response()->json($response, 200);
  1319. }
  1320. }
  1321. }else{
  1322. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1323. $compound->status = $request->status;
  1324. $compound->catatan_dari_admin = $request->remark;
  1325. $compound->amount_payment = $request->amount;
  1326. $compound->update_by = $request->current_id;
  1327. $saved = $compound->save();
  1328. if($saved){
  1329. $gDate = $compound->created_at->format('F Y');
  1330. $historyData = [
  1331. 'tarikh_kumpulan' => $gDate,
  1332. ];
  1333. $subHistory = [
  1334. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1335. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1336. '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>",
  1337. ];
  1338. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1339. if(!empty($groupByDate)){
  1340. $groupByDate->subhistory()->create($subHistory);
  1341. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1342. }else{
  1343. $history = History::create($historyData);
  1344. $history->subhistory()->create($subHistory);
  1345. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1346. }
  1347. if($request->status == "Berbayar"){
  1348. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1349. }else{
  1350. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1351. }
  1352. }else{
  1353. $response = [
  1354. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1355. ];
  1356. return response()->json($response, 200);
  1357. }
  1358. }else{
  1359. if($request->remark != ''){
  1360. $compound->catatan_dari_admin = $request->remark;
  1361. $compound->update_by = $request->current_id;
  1362. $compound->save();
  1363. $saved = $compound->save();
  1364. if($saved){
  1365. $gDate = $compound->created_at->format('F Y');
  1366. $historyData = [
  1367. 'tarikh_kumpulan' => $gDate,
  1368. ];
  1369. $subHistory = [
  1370. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1371. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1372. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1373. ];
  1374. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1375. if(!empty($groupByDate)){
  1376. $groupByDate->subhistory()->create($subHistory);
  1377. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1378. }else{
  1379. $history = History::create($historyData);
  1380. $history->subhistory()->create($subHistory);
  1381. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1382. }
  1383. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1384. }else{
  1385. $response = [
  1386. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1387. ];
  1388. return response()->json($response, 200);
  1389. }
  1390. }else{
  1391. $response = [
  1392. 'success' => false, 'message' => 'Tiada kemaskini!',
  1393. ];
  1394. return response()->json($response, 200);
  1395. }
  1396. }
  1397. }
  1398. }else{
  1399. $response = [
  1400. 'success' => false,
  1401. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  1402. ];
  1403. return response()->json($response, 200);
  1404. }
  1405. }
  1406. /**
  1407. * Remove the specified resource from storage.
  1408. *
  1409. * @param int $id
  1410. * @return \Illuminate\Http\Response
  1411. */
  1412. public function destroy($id)
  1413. {
  1414. //
  1415. }
  1416. }