Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CompoundResourceController.php 73KB

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