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

CompoundResourceController.php 63KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  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. $compound = $compound->where('kpd',$kpd);
  148. return $compound;
  149. }else{
  150. $compound = $compound->whereIn('status', ['Belum Bayar', 'Berbayar', 'Batal']);
  151. return $compound;
  152. }
  153. }
  154. private function searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$day3, $day7){
  155. $compound = $this->searchKpd($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$day3, $day7);
  156. if(!empty($company_no)){
  157. $compound = $compound->where('no_daftar_syarikat','LIKE',$company_no);
  158. return $compound;
  159. }else{
  160. return $compound;
  161. }
  162. }
  163. private function searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$day3, $day7){
  164. $compound = $this->searchCompanyNo($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$day3, $day7);
  165. if(!empty($nric)){
  166. $compound = $compound->where('identity',$nric);
  167. return $compound;
  168. }else{
  169. return $compound;
  170. }
  171. }
  172. private function searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$day3, $day7){
  173. $compound = $this->searchNric($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$day3, $day7);
  174. if(!empty($license)){
  175. $compound = $compound->where('no_akaun_lesen', 'exists', true)->where('no_akaun_lesen',$license);
  176. return $compound;
  177. }else{
  178. return $compound;
  179. }
  180. }
  181. private function searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$day3, $day7){
  182. $compound = $this->searchLesen($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$day3, $day7);
  183. if(!empty($namaP)){
  184. $compound = $compound->where('nama', 'LIKE', "%{$namaP}%");
  185. return $compound;
  186. }else{
  187. return $compound;
  188. }
  189. }
  190. 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){
  191. $compound = $this->searchName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$day3, $day7);
  192. if(!empty($company_name)){
  193. $compound = $compound->where('nama_syarikat', 'exists', true)->where('nama_syarikat', 'LIKE', '%{$company_name%}');
  194. return $compound;
  195. }else{
  196. return $compound;
  197. }
  198. }
  199. public function index(Request $request)
  200. {
  201. // $per_page = '';
  202. // $kpd = '';
  203. // $modul = '02';
  204. // $status = 'All';
  205. // $jenis = 'Pelbagai_JPB';
  206. // if(!empty($request->department)){
  207. // $department = array (
  208. // 0 => '5df355f891d6e66b9c5e626d',
  209. // 1 => '5df721c5cde7fd741433c6b2',
  210. // 2 => '5df722a24636f4594f4a3c3d',
  211. // 3 => '5f17a31795dbfd3320761bfe',
  212. // 4 => '5f3b872fea58cb3c1b0e7b8d',
  213. // );
  214. // }else {
  215. // $department = [];
  216. // }
  217. // // $start_date = '';
  218. // // $end_date = '';
  219. // $start_date = '2020-08-29';
  220. // $end_date = '2020-08-29';
  221. // $enforcer = 'All';
  222. // $faulty = 'All';
  223. // $plate_no = strtolower('');
  224. // $company_no = strtolower('');
  225. // $nric = '';
  226. // $license = '';
  227. // $namaP = '';
  228. // $company_name = '';
  229. // $day3 = 3;
  230. // $day7 = '';
  231. /////////////////////////////////////////////////////////////////////////////////
  232. $per_page = $request->per_page;
  233. $kpd = $request->kpd;
  234. $modul = $request->modul;
  235. $status = $request->status;
  236. $jenis = $request->type;
  237. if(!empty($request->department)){
  238. $department = json_decode($request->department);
  239. }else {
  240. $department = [];
  241. }
  242. $start_date = $request->start_date;
  243. $end_date = $request->end_date;
  244. $enforcer = $request->enforcer;
  245. $faulty = $request->faulty;
  246. $plate_no = strtolower($request->plate_no);
  247. $company_no = strtolower($request->company_no);
  248. $nric = $request->nric;
  249. $license = $request->license;
  250. $namaP = $request->nameP;
  251. $company_name = $request->company_name;
  252. $day3='';
  253. $day7='';
  254. if ($request->has('day3')) {
  255. $day3 = $request->day3; //has() checks if param exist and filled
  256. }
  257. if ($request->has('day7')) {
  258. $day3 = $request->day7; //has() checks if param exist and filled
  259. }
  260. // if (!empty($start_date)) {
  261. // }
  262. $nested_data = array();
  263. $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();
  264. // info($compound);
  265. return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
  266. ->addColumn('index', function($row) {
  267. $curr = Carbon::now();
  268. $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
  269. if($curr->diffInDays($dtC) <= 3){
  270. $html = 'New';
  271. }else{ $html = ''; }
  272. return $html;
  273. })->addColumn('status_kemaskini', function($row) {
  274. $data = '';
  275. if($row['status'] == 'Berbayar'){
  276. $data = '<b>'.$row['status'].'</b><div style="margin-top: 8px"><span>Bayaran: </span><br/>';
  277. $data .= 'RM '.$row['amount_payment'].'</div>';
  278. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  279. if($row['updated_by'] !== null ){
  280. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  281. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  282. }else {
  283. if(!empty($row['tarikh_bayar']) && $row['tarikh_bayar'] != ''){
  284. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  285. $data .= $row['tarikh_bayar'].' <br/>'.$row['updates_by'].'</div>';
  286. }else {
  287. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  288. $data .= $row['updated_at'].' <br/>'.$row['updates_by'].'</div>';
  289. }
  290. }
  291. }else if($row['status'] == 'Belum Bayar' && $row['updated_by'] !== null){
  292. $data = '<b>'.$row['status'].'</b>';
  293. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  294. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  295. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  296. }else if($row['status'] == 'Batal' && $row['updated_by'] !== null){
  297. $data = '<b>'.$row['status'].'</b>';
  298. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  299. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  300. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  301. }else if($row['status'] == 'Buang' && $row['updated_by'] !== null){
  302. $data = '<b>'.$row['status'].'</b>';
  303. $data .= '<div style="margin-top: 8px"><span>Catatan: </span><br/>'.$row['catatan_dari_admin'].'</div>';
  304. $data .= '<div style="margin-top: 8px"><span>Kemaskini: </span><br/>';
  305. $data .= $row['updated_at'].' <br/>'.$row['updated_by']['no_badan'].'</div>';
  306. }
  307. else
  308. {
  309. $data = $row['status'];
  310. }
  311. return $data;
  312. })->addColumn('kesalahan', function($row) {
  313. $data = '<b>Seksyen '.$row['faulty_skter'].'</b><br/>'.$row['faulty_name'];
  314. return $data;
  315. })->rawColumns(['index','status_kemaskini','kesalahan'])->make(true);
  316. }
  317. public function notice_index(Request $request)
  318. {
  319. $per_page = '';
  320. $kpd = '';
  321. $modul = '02';
  322. $status = 'All';
  323. $jenis = 'Pelbagai_JPB';
  324. $department = array (
  325. 0 => '5df355f891d6e66b9c5e626d',
  326. 1 => '5df721c5cde7fd741433c6b2',
  327. 2 => '5df722a24636f4594f4a3c3d',
  328. 3 => '5f17a31795dbfd3320761bfe',
  329. 4 => '5f3b872fea58cb3c1b0e7b8d',
  330. );
  331. $start_date = '2020-08-18';
  332. $end_date = '2020-09-20';
  333. $enforcer = 'All';
  334. $faulty = 'All';
  335. $plate_no = strtolower('');
  336. $company_no = strtolower('');
  337. $nric = '';
  338. $license = '';
  339. $namaP = '';
  340. $company_name = '';
  341. ###############################################################################################################
  342. // $per_page = $request->per_page;
  343. // $kpd = $request->kpd;
  344. // $modul = $request->modul;
  345. // $status = $request->status;
  346. // $jenis = $request->type;
  347. // if(!empty($request->department)){
  348. // $department = json_decode($request->department);
  349. // }else {
  350. // $department = [];
  351. // }
  352. // $start_date = $request->start_date;
  353. // $end_date = $request->end_date;
  354. // $enforcer = $request->enforcer;
  355. // $faulty = $request->faulty;
  356. // $plate_no = strtolower($request->plate_no);
  357. // $company_no = strtolower($request->company_no);
  358. // $nric = $request->nric;
  359. // $license = $request->license;
  360. // $namaP = $request->nameP;
  361. // $company_name = $request->company_name;
  362. $nested_data = array();
  363. $compound = $this->searchCompanyName($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date,$department,$plate_no,$kpd,$company_no,$nric,$license,$namaP,$company_name)->orderBy('created_at','ASC')->get();
  364. // return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
  365. // ->addColumn('index', function($row) {
  366. // $curr = Carbon::now();
  367. // $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
  368. // if($curr->diffInDays($dtC) <= 3){
  369. // $html = 'New';
  370. // }else{ $html = ''; }
  371. // return $html;
  372. // });
  373. if (!empty($compound)) {
  374. foreach ($compound as $key => $c) {
  375. $faulty = Faulty::where('_id', $c->seksyen_kesalahan)->first();
  376. $enforcer = StaffDetail::where('_id', $c->dikeluarkan)->first();
  377. array_push($nested_data, array(
  378. 'index' => '',
  379. 'modul' => $c->modul,
  380. 'kpd' => $c->kpd,
  381. 'jenis' => $c->jenis,
  382. 'masa' => $c->created_at,
  383. 'kesalahan' => $faulty->nama,
  384. 'nric' => $c->identity,
  385. 'nama' => $c->nama,
  386. 'penguatkuasa' => $enforcer->full_name,
  387. // 'tindakan' =>
  388. ));
  389. }
  390. }
  391. return \DataTables::of($nested_data)->addIndexcolumn()->make(true);
  392. }
  393. /**
  394. * Show the form for creating a new resource.
  395. *
  396. * @return \Illuminate\Http\Response
  397. */
  398. public function create()
  399. {
  400. //
  401. }
  402. /**
  403. * Store a created compound from notice.
  404. *
  405. * @param \Illuminate\Http\Request $request
  406. * @return \Illuminate\Http\Response
  407. */
  408. public function store(Request $request)
  409. {
  410. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  411. if(empty($staff)){
  412. return $this->sendError('Invalid', 'Staff not existed');
  413. }else {
  414. $saved ='';
  415. $kpd = '';
  416. $no_siri = '';
  417. $data = array();
  418. if($request->jenis == 'Parkir')
  419. {
  420. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  421. if(!empty($faulty)){
  422. $countKPD = $this->compound->withTrashed()->count();
  423. do {
  424. $countKPD = $countKPD + 1;
  425. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  426. $kpd = $countKPD;
  427. $no_siri = date('yn').'-'.$countKPD;
  428. $fileData = [
  429. 'no_siri' => $no_siri,
  430. ];
  431. //only for compound parkir
  432. $compoundData = [
  433. 'jenis' => 'Parkir',
  434. 'kpd' => $kpd,
  435. 'nama' => '-',
  436. 'identity' => '-',
  437. 'alamat' => '-',
  438. "no_plate" => strtolower($request->no_plate),
  439. "no_cukai_jalan" => $request->noCukaijalan,
  440. "jenis_kenderaan" => $request->jenisKenderaan,
  441. "model_kenderaan" => $request->modelKenderaan,
  442. "warna_kenderaan" => $request->warnakenderaan,
  443. "nama_kawasan" => $request->namaKawasan,
  444. "nama_taman" => $request->namaTaman,
  445. "nama_jalan" => $request->namaJalan,
  446. "no_parking" => $request->noParking,
  447. "catatan" => $request->catatan,
  448. "lokasi_kejadian" => '-',
  449. 'latlong' => $request->Latlong,
  450. 'jbkod' => $request->jabatan,
  451. 'akta' => $faulty->deed_law_id,
  452. 'seksyen_kesalahan' => $faulty->_id,
  453. 'jumlah_asal_kompaun' => $faulty->amount,
  454. 'jumlah_kemaskini_kompaun' => '',
  455. 'dikeluarkan' => $staff->_id,
  456. "status" => 'Belum Bayar',
  457. "amount_payment" => '',
  458. "receipt" => '',
  459. "modul" => '03',
  460. "penguatkuasa" => '',
  461. "cpn_created" => Carbon::now()->toDateTimeString(),
  462. ];
  463. $file = ConfidentialFile::create($fileData);
  464. $saved = $file->compound()->create($compoundData);
  465. }
  466. }elseif(($request->jenis == 'Pelbagai_KT') || ($request->jenis == 'Pelbagai_JPB') || ($request->jenis == 'Pelbagai_PA') ||
  467. ($request->jenis == 'Pelbagai_LESEN')){
  468. $kpd = $request->kpd;
  469. $compound = Compound::where('jenis', $request->jenis)->where('kpd', $kpd)->first();
  470. if (!empty($compound)) {
  471. if(!($compound->modul == '03'))
  472. {
  473. if($request->jenis == 'Pelbagai_KT'){
  474. $compound->jenis = $request->jenis;
  475. $compound->nama = $request->namaP;
  476. $compound->identity = $request->noIc;
  477. $compound->nama_syarikat = $request->namaS;
  478. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  479. $compound->alamat = $request->alamat;
  480. $compound->no_plate = $request->no_plate;
  481. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  482. // $compound->nama_kawasan = $request->namaKawasan;
  483. // $compound->nama_taman = $request->namaTaman;
  484. // $compound->nama_jalan = $request->namaJalan;
  485. $compound->catatan = $request->catatan;
  486. $compound->latlong = $request->Latlong;
  487. // $compound->akta = $faulty->deed_law_id;
  488. // $compound->seksyen_kesalahan = $faulty->_id;
  489. // $compound->jumlah_asal_kompaun = $faulty->amount;
  490. $compound->dikeluarkan_ = $staff->_id;
  491. $compound->status = 'Belum Bayar';
  492. $compound->modul = '03';
  493. $compound->no_telefon = $request->tel;
  494. $compound->no_akaun_lesen = $request->lesen;
  495. $compound->cpn_created = Carbon::now()->toDateTimeString();
  496. }elseif($request->jenis == 'Pelbagai_JPB'){
  497. $compound->jenis = $request->jenis;
  498. $compound->nama = $request->namaP;
  499. $compound->identity = $request->noIc;
  500. $compound->nama_syarikat = $request->namaS;
  501. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  502. $compound->alamat = $request->alamat;
  503. $compound->no_plate = $request->no_plate;
  504. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  505. // $compound->nama_kawasan => $request->namaKawasan;
  506. // $compound->nama_taman => $request->namaTaman;
  507. // $compound->nama_jalan => $request->namaJalan;
  508. $compound->catatan = $request->catatan;
  509. $compound->latlong = $request->Latlong;
  510. // $compound->akta => $faulty->deed_law_id;
  511. // $compound->seksyen_kesalahan => $faulty->_id;
  512. // $compound->jumlah_asal_kompaun => $faulty->amount;
  513. $compound->dikeluarkan_ = $staff->_id;
  514. $compound->status = 'Belum Bayar';
  515. $compound->modul = '03';
  516. $compound->no_telefon = $request->tel;
  517. $compound->no_akaun_lesen = $request->lesen;
  518. $compound->cpn_created = Carbon::now()->toDateTimeString();
  519. }elseif($request->jenis == 'Pelbagai_PA'){
  520. $compound->jenis = $request->jenis;
  521. $compound->nama = $request->namaP;
  522. $compound->identity = $request->noIc;
  523. $compound->nama_syarikat = $request->namaS;
  524. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  525. $compound->alamat = $request->alamat;
  526. $compound->no_plate = $request->no_plate;
  527. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  528. // $compound->nama_kawasan = $request->namaKawasan;
  529. // $compound->nama_taman = $request->namaTaman;
  530. // $compound->nama_jalan = $request->namaJalan;
  531. $compound->catatan = $request->catatan;
  532. $compound->latlong = $request->Latlong;
  533. // $compound->akta = $faulty->deed_law_id;
  534. // $compound->seksyen_kesalahan = $faulty->_id;
  535. // $compound->jumlah_asal_kompaun = $faulty->amount;
  536. $compound->dikeluarkan_ = $staff->_id;
  537. $compound->status = 'Belum Bayar';
  538. $compound->modul = '03';
  539. $compound->no_telefon = $request->tel;
  540. $compound->no_akaun_lesen = $request->lesen;
  541. $compound->bil_haiwan = $request->lesen;
  542. $compound->cpn_created = Carbon::now()->toDateTimeString();
  543. }elseif($request->jenis == 'Pelbagai_LESEN'){
  544. $compound->jenis = $request->jenis;
  545. $compound->nama = $request->namaP;
  546. $compound->identity = $request->noIc;
  547. $compound->nama_syarikat = $request->namaS;
  548. $compound->no_daftar_syarikat = strtolower($request->daftarNo);
  549. $compound->alamat = $request->alamat;
  550. $compound->no_plate = $request->no_plate;
  551. $compound->no_cukai_jalan = $request->no_cukai_jalan;
  552. // $compound->nama_kawasan = $request->namaKawasan;
  553. // $compound->nama_taman = $request->namaTaman;
  554. // $compound->nama_jalan = $request->namaJalan;
  555. $compound->catatan = $request->catatan;
  556. $compound->latlong = $request->Latlong;
  557. // $compound->akta = $faulty->deed_law_id;
  558. // $compound->seksyen_kesalahan = $faulty->_id;
  559. // $compound->jumlah_asal_kompaun = $faulty->amount;
  560. $compound->dikeluarkan_ = $staff->_id;
  561. $compound->status = 'Belum Bayar';
  562. $compound->modul = '03';
  563. $compound->no_telefon = $request->tel;
  564. $compound->no_akaun_lesen = $request->lesen;
  565. $compound->cpn_created = Carbon::now()->toDateTimeString();
  566. }
  567. $saved = $compound->save();
  568. }
  569. else
  570. {
  571. return $this->sendResponse('', 'Kompaun ini telah dikeluarkan!');
  572. }
  573. }
  574. }
  575. if($saved){
  576. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  577. // if(!empty($compound)){
  578. dispatch(new UpdateCompoundPrice($kpd));
  579. // $tawaran = '';
  580. // if($compound->jumlah_kemaskini_kompaun != ''){
  581. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  582. // }else{
  583. // $tawaran = $compound->jumlah_asal_kompaun;
  584. // }
  585. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  586. array_push($data, array('kpd' => $kpd));
  587. // $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  588. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  589. // }
  590. }
  591. }
  592. }
  593. /*********************************************
  594. | Store a newly created notice
  595. *********************************************/
  596. public function storeNotice(Request $request)
  597. {
  598. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  599. if(empty($staff)){
  600. return $this->sendError('Invalid', 'Staff not existed');
  601. }else {
  602. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  603. if(!empty($faulty)){
  604. $data = array();
  605. $countKPD = $this->compound->withTrashed()->count();
  606. do {
  607. $countKPD = $countKPD + 1;
  608. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  609. $kpd = $countKPD;
  610. $no_siri = date('yn').'-'.$countKPD;
  611. $fileData = [
  612. 'no_siri' => $no_siri,
  613. ];
  614. if($request->jenis == 'Parkir'){
  615. $compoundData = [
  616. 'jenis' => 'Parkir',
  617. 'kpd' => $kpd,
  618. 'nama' => '-',
  619. 'identity' => '-',
  620. 'alamat' => '-',
  621. "no_plate" => strtolower($request->no_plate),
  622. "no_cukai_jalan" => $request->noCukaijalan,
  623. "jenis_kenderaan" => $request->jenisKenderaan,
  624. "model_kenderaan" => $request->modelKenderaan,
  625. "warna_kenderaan" => $request->warnakenderaan,
  626. "nama_kawasan" => $request->namaKawasan,
  627. "nama_taman" => $request->namaTaman,
  628. "nama_jalan" => $request->namaJalan,
  629. "no_parking" => $request->noParking,
  630. "catatan" => $request->catatan,
  631. "lokasi_kejadian" => '-',
  632. 'latlong' => $request->Latlong,
  633. 'jbkod' => $request->jabatan,
  634. 'akta' => $faulty->deed_law_id,
  635. 'seksyen_kesalahan' => $faulty->_id,
  636. 'jumlah_asal_kompaun' => $faulty->amount,
  637. 'jumlah_kemaskini_kompaun' => '',
  638. 'dikeluarkan' => $staff->_id,
  639. "status" => 'Belum Bayar',
  640. "amount_payment" => '',
  641. "receipt" => '',
  642. "modul" => $request->modul,
  643. "penguatkuasa" => '',
  644. "notis_created" => Carbon::now()->toDateTimeString(),
  645. ];
  646. }elseif($request->jenis == 'Pelbagai_KT'){
  647. $compoundData = [
  648. 'jenis' => $request->jenis,
  649. 'kpd' => $kpd,
  650. 'nama' => $request->namaP,
  651. 'identity' => $request->noIc,
  652. 'nama_syarikat' => $request->namaS,
  653. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  654. 'alamat' => $request->alamat,
  655. "no_plate" => $request->no_plate,
  656. "no_cukai_jalan" => $request->no_cukai_jalan,
  657. "nama_kawasan" => $request->namaKawasan,
  658. "nama_taman" => $request->namaTaman,
  659. "nama_jalan" => $request->namaJalan,
  660. "catatan" => $request->catatan,
  661. "lokasi_kejadian" => '-',
  662. 'latlong' => $request->Latlong,
  663. 'jbkod' => $request->jabatan,
  664. 'akta' => $faulty->deed_law_id,
  665. 'seksyen_kesalahan' => $faulty->_id,
  666. 'jumlah_asal_kompaun' => $faulty->amount,
  667. 'jumlah_kemaskini_kompaun' => '',
  668. 'dikeluarkan' => $staff->_id,
  669. "status" => 'Belum Bayar',
  670. "amount_payment" => '',
  671. "receipt" => '',
  672. "modul" => $request->modul,
  673. "penguatkuasa" => '',
  674. "no_telefon" => $request->tel,
  675. "no_akaun_lesen" => $request->lesen,
  676. "maklumat_tambahan" => '-',
  677. "tindakan" => $request->tindakan,
  678. "tempoh" => $request->tempoh,
  679. "notis_created" => Carbon::now()->toDateTimeString(),
  680. ];
  681. }elseif($request->jenis == 'Pelbagai_JPB'){
  682. $compoundData = [
  683. 'jenis' => $request->jenis,
  684. 'kpd' => $kpd,
  685. 'nama' => $request->namaP,
  686. 'identity' => $request->noIc,
  687. 'nama_syarikat' => $request->namaS,
  688. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  689. 'alamat' => $request->alamat,
  690. "no_plate" => $request->no_plate,
  691. "no_cukai_jalan" => $request->no_cukai_jalan,
  692. "nama_kawasan" => $request->namaKawasan,
  693. "nama_taman" => $request->namaTaman,
  694. "nama_jalan" => $request->namaJalan,
  695. "catatan" => $request->catatan,
  696. "lokasi_kejadian" => '-',
  697. 'latlong' => $request->Latlong,
  698. 'jbkod' => $request->jabatan,
  699. 'akta' => $faulty->deed_law_id,
  700. 'seksyen_kesalahan' => $faulty->_id,
  701. 'jumlah_asal_kompaun' => $faulty->amount,
  702. 'jumlah_kemaskini_kompaun' => '',
  703. 'dikeluarkan' => $staff->_id,
  704. "status" => 'Belum Bayar',
  705. "amount_payment" => '',
  706. "receipt" => '',
  707. "modul" => $request->modul,
  708. "penguatkuasa" => '',
  709. "no_telefon" => $request->tel,
  710. "no_akaun_lesen" => $request->lesen,
  711. "maklumat_tambahan" => '-',
  712. "tindakan" => $request->tindakan,
  713. "tempoh" => $request->tempoh,
  714. "notis_created" => Carbon::now()->toDateTimeString(),
  715. ];
  716. }
  717. elseif($request->jenis == 'Pelbagai_LESEN'){
  718. $compoundData = [
  719. 'jenis' => $request->jenis,
  720. 'kpd' => $kpd,
  721. 'nama' => $request->namaP,
  722. 'identity' => $request->noIc,
  723. 'nama_syarikat' => $request->namaS,
  724. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  725. 'alamat' => $request->alamat,
  726. "no_plate" => $request->no_plate,
  727. "no_cukai_jalan" => $request->no_cukai_jalan,
  728. "nama_kawasan" => $request->namaKawasan,
  729. "nama_taman" => $request->namaTaman,
  730. "nama_jalan" => $request->namaJalan,
  731. "catatan" => $request->catatan,
  732. "lokasi_kejadian" => '-',
  733. 'latlong' => $request->Latlong,
  734. 'jbkod' => $request->jabatan,
  735. 'akta' => $faulty->deed_law_id,
  736. 'seksyen_kesalahan' => $faulty->_id,
  737. 'jumlah_asal_kompaun' => $faulty->amount,
  738. 'jumlah_kemaskini_kompaun' => '',
  739. 'dikeluarkan' => $staff->_id,
  740. "status" => 'Belum Bayar',
  741. "amount_payment" => '',
  742. "receipt" => '',
  743. "modul" => $request->modul,
  744. "penguatkuasa" => '',
  745. "no_telefon" => $request->tel,
  746. "no_akaun_lesen" => $request->lesen,
  747. "maklumat_tambahan" => '-',
  748. "notis_created" => Carbon::now()->toDateTimeString(),
  749. ];
  750. }
  751. elseif($request->jenis == 'Pelbagai_PA'){
  752. $compoundData = [
  753. 'jenis' => $request->jenis,
  754. 'kpd' => $kpd,
  755. 'nama' => $request->namaP,
  756. 'identity' => $request->noIc,
  757. 'nama_syarikat' => $request->namaS,
  758. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  759. 'alamat' => $request->alamat,
  760. "no_plate" => $request->no_plate,
  761. "no_cukai_jalan" => $request->no_cukai_jalan,
  762. "nama_kawasan" => $request->namaKawasan,
  763. "nama_taman" => $request->namaTaman,
  764. "nama_jalan" => $request->namaJalan,
  765. "catatan" => $request->catatan,
  766. "lokasi_kejadian" => '-',
  767. 'latlong' => $request->Latlong,
  768. 'jbkod' => $request->jabatan,
  769. 'akta' => $faulty->deed_law_id,
  770. 'seksyen_kesalahan' => $faulty->_id,
  771. 'jumlah_asal_kompaun' => $faulty->amount,
  772. 'jumlah_kemaskini_kompaun' => '',
  773. 'dikeluarkan' => $staff->_id,
  774. "status" => 'Belum Bayar',
  775. "amount_payment" => '',
  776. "receipt" => '',
  777. "modul" => $request->modul,
  778. "penguatkuasa" => '',
  779. "no_telefon" => $request->tel,
  780. "no_akaun_lesen" => $request->lesen,
  781. "maklumat_tambahan" => '-',
  782. "bil_haiwan" => $request->bil_haiwan,
  783. "notis_created" => Carbon::now()->toDateTimeString(),
  784. ];
  785. }
  786. $file = ConfidentialFile::create($fileData);
  787. $saved = $file->compound()->create($compoundData);
  788. if($saved){
  789. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  790. // if(!empty($compound)){
  791. dispatch(new UpdateCompoundPrice($kpd));
  792. // $tawaran = '';
  793. // if($compound->jumlah_kemaskini_kompaun != ''){
  794. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  795. // }else{
  796. // $tawaran = $compound->jumlah_asal_kompaun;
  797. // }
  798. $this->dispatch(new StoreNotice($request->all(), $kpd, $staff->_id, $no_siri));
  799. array_push($data, array('kpd' => $kpd));
  800. return $this->sendResponse($data, 'Berjaya simpan rekod notis!');
  801. // }
  802. }
  803. }
  804. }
  805. }
  806. /**
  807. * Store a newly created compound (parkir, KT, JPB).
  808. *
  809. * @param \Illuminate\Http\Request $request
  810. * @return \Illuminate\Http\Response
  811. */
  812. public function storeCompound(Request $request)
  813. {
  814. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  815. if(empty($staff)){
  816. return $this->sendError('Invalid', 'Staff not existed');
  817. }else {
  818. $data = array();
  819. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  820. if(!empty($faulty)){
  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. //only for compound parkir
  833. $compoundData = [
  834. 'jenis' => 'Parkir',
  835. 'kpd' => $kpd,
  836. 'nama' => '-',
  837. 'identity' => '-',
  838. 'alamat' => '-',
  839. "no_plate" => strtolower($request->no_plate),
  840. "no_cukai_jalan" => $request->noCukaijalan,
  841. "jenis_kenderaan" => $request->jenisKenderaan,
  842. "model_kenderaan" => $request->modelKenderaan,
  843. "warna_kenderaan" => $request->warnakenderaan,
  844. "nama_kawasan" => $request->namaKawasan,
  845. "nama_taman" => $request->namaTaman,
  846. "nama_jalan" => $request->namaJalan,
  847. "no_parking" => $request->noParking,
  848. "catatan" => $request->catatan,
  849. "lokasi_kejadian" => '-',
  850. 'latlong' => $request->Latlong,
  851. 'jbkod' => $request->jabatan,
  852. 'akta' => $faulty->deed_law_id,
  853. 'seksyen_kesalahan' => $faulty->_id,
  854. 'jumlah_asal_kompaun' => $faulty->amount,
  855. 'jumlah_kemaskini_kompaun' => '',
  856. 'dikeluarkan' => $staff->_id,
  857. "status" => 'Belum Bayar',
  858. "amount_payment" => '',
  859. "receipt" => '',
  860. "modul" => '03',
  861. "penguatkuasa" => '',
  862. "cpn_created" => Carbon::now()->toDateTimeString(),
  863. ];
  864. }
  865. if ($request->jenis == 'Pelbagai_KT') {
  866. $compoundData = [
  867. 'jenis' => $request->jenis,
  868. 'kpd' => $kpd,
  869. 'nama' => $request->namaP,
  870. 'identity' => $request->noIc,
  871. 'nama_syarikat' => $request->namaS,
  872. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  873. 'alamat' => $request->alamat,
  874. "no_plate" => $request->no_plate,
  875. "no_cukai_jalan" => $request->no_cukai_jalan,
  876. "nama_kawasan" => $request->namaKawasan,
  877. "nama_taman" => $request->namaTaman,
  878. "nama_jalan" => $request->namaJalan,
  879. "catatan" => $request->catatan,
  880. "lokasi_kejadian" => '-',
  881. 'latlong' => $request->Latlong,
  882. 'jbkod' => $request->jabatan,
  883. 'akta' => $faulty->deed_law_id,
  884. 'seksyen_kesalahan' => $faulty->_id,
  885. 'jumlah_asal_kompaun' => $faulty->amount,
  886. 'jumlah_kemaskini_kompaun' => '',
  887. 'dikeluarkan' => $staff->_id,
  888. "status" => 'Belum Bayar',
  889. "amount_payment" => '',
  890. "receipt" => '',
  891. "modul" => $request->modul,
  892. "penguatkuasa" => '',
  893. "no_telefon" => $request->tel,
  894. "no_akaun_lesen" => $request->lesen,
  895. "maklumat_tambahan" => '-',
  896. "tindakan" => $request->tindakan,
  897. "tempoh" => $request->tempoh,
  898. "notis_created" => Carbon::now()->toDateTimeString(),
  899. ];
  900. }
  901. elseif ($request->jenis == 'Pelbagai_JPB') {
  902. $compoundData = [
  903. 'jenis' => $request->jenis,
  904. 'kpd' => $kpd,
  905. 'nama' => $request->namaP,
  906. 'identity' => $request->noIc,
  907. 'nama_syarikat' => $request->namaS,
  908. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  909. 'alamat' => $request->alamat,
  910. "no_plate" => $request->no_plate,
  911. "no_cukai_jalan" => $request->no_cukai_jalan,
  912. "nama_kawasan" => $request->namaKawasan,
  913. "nama_taman" => $request->namaTaman,
  914. "nama_jalan" => $request->namaJalan,
  915. "catatan" => $request->catatan,
  916. "lokasi_kejadian" => '-',
  917. 'latlong' => $request->Latlong,
  918. 'jbkod' => $request->jabatan,
  919. 'akta' => $faulty->deed_law_id,
  920. 'seksyen_kesalahan' => $faulty->_id,
  921. 'jumlah_asal_kompaun' => $faulty->amount,
  922. 'jumlah_kemaskini_kompaun' => '',
  923. 'dikeluarkan' => $staff->_id,
  924. "status" => 'Belum Bayar',
  925. "amount_payment" => '',
  926. "receipt" => '',
  927. "modul" => $request->modul,
  928. "penguatkuasa" => '',
  929. "no_telefon" => $request->tel,
  930. "no_akaun_lesen" => $request->lesen,
  931. "maklumat_tambahan" => '-',
  932. "tindakan" => $request->tindakan,
  933. "tempoh" => $request->tempoh,
  934. "notis_created" => Carbon::now()->toDateTimeString(),
  935. ];
  936. }
  937. elseif ($request->jenis == 'Pelbagai_LESEN') {
  938. $compoundData = [
  939. 'jenis' => $request->jenis,
  940. 'kpd' => $kpd,
  941. 'nama' => $request->namaP,
  942. 'identity' => $request->noIc,
  943. 'nama_syarikat' => $request->namaS,
  944. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  945. 'alamat' => $request->alamat,
  946. "no_plate" => $request->no_plate,
  947. "no_cukai_jalan" => $request->no_cukai_jalan,
  948. "nama_kawasan" => $request->namaKawasan,
  949. "nama_taman" => $request->namaTaman,
  950. "nama_jalan" => $request->namaJalan,
  951. "catatan" => $request->catatan,
  952. "lokasi_kejadian" => '-',
  953. 'latlong' => $request->Latlong,
  954. 'jbkod' => $request->jabatan,
  955. 'akta' => $faulty->deed_law_id,
  956. 'seksyen_kesalahan' => $faulty->_id,
  957. 'jumlah_asal_kompaun' => $faulty->amount,
  958. 'jumlah_kemaskini_kompaun' => '',
  959. 'dikeluarkan' => $staff->_id,
  960. "status" => 'Belum Bayar',
  961. "amount_payment" => '',
  962. "receipt" => '',
  963. "modul" => $request->modul,
  964. "penguatkuasa" => '',
  965. "no_telefon" => $request->tel,
  966. "no_akaun_lesen" => $request->lesen,
  967. "maklumat_tambahan" => '-',
  968. "notis_created" => Carbon::now()->toDateTimeString(),
  969. ];
  970. }
  971. else if($request->jenis == 'Pelbagai_PA'){
  972. $compoundData = [
  973. 'jenis' => $request->jenis,
  974. 'kpd' => $kpd,
  975. 'nama' => $request->namaP,
  976. 'identity' => $request->noIc,
  977. 'nama_syarikat' => $request->namaS,
  978. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  979. 'alamat' => $request->alamat,
  980. "no_plate" => $request->no_plate,
  981. "no_cukai_jalan" => $request->no_cukai_jalan,
  982. "nama_kawasan" => $request->namaKawasan,
  983. "nama_taman" => $request->namaTaman,
  984. "nama_jalan" => $request->namaJalan,
  985. "catatan" => $request->catatan,
  986. "lokasi_kejadian" => '-',
  987. 'latlong' => $request->Latlong,
  988. 'jbkod' => $request->jabatan,
  989. 'akta' => $faulty->deed_law_id,
  990. 'seksyen_kesalahan' => $faulty->_id,
  991. 'jumlah_asal_kompaun' => $faulty->amount,
  992. 'jumlah_kemaskini_kompaun' => '',
  993. 'dikeluarkan' => $staff->_id,
  994. "status" => 'Belum Bayar',
  995. "amount_payment" => '',
  996. "receipt" => '',
  997. "modul" => $request->modul,
  998. "penguatkuasa" => '',
  999. "no_telefon" => $request->tel,
  1000. "no_akaun_lesen" => $request->lesen,
  1001. "maklumat_tambahan" => '-',
  1002. "bil_haiwan" => $request->bil_haiwan,
  1003. "notis_created" => Carbon::now()->toDateTimeString(),
  1004. ];
  1005. }
  1006. $file = ConfidentialFile::create($fileData);
  1007. $saved = $file->compound()->create($compoundData);
  1008. }
  1009. if($saved){
  1010. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  1011. // if(!empty($compound)){
  1012. dispatch(new UpdateCompoundPrice($kpd));
  1013. // $tawaran = '';
  1014. // if($compound->jumlah_kemaskini_kompaun != ''){
  1015. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  1016. // }else{
  1017. // $tawaran = $compound->jumlah_asal_kompaun;
  1018. // }
  1019. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  1020. array_push($data, array('kpd' => $kpd));
  1021. // $this->dispatch(new StoreCompoundEPBT($request->all(), $kpd, $staff->StaffDetail->full_name, $staff->StaffDetail->no_badan, $faulty->nama));
  1022. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  1023. // }
  1024. }
  1025. }
  1026. }
  1027. /**
  1028. * Display the specified resource.
  1029. *
  1030. * @param int $id
  1031. * @return \Illuminate\Http\Response
  1032. */
  1033. public function show($id)
  1034. {
  1035. //
  1036. }
  1037. /**
  1038. * Show the form for editing the specified resource.
  1039. *
  1040. * @param int $id
  1041. * @return \Illuminate\Http\Response
  1042. */
  1043. public function edit($id)
  1044. {
  1045. //
  1046. }
  1047. /**
  1048. * Update the specified resource in storage.
  1049. *
  1050. * @param \Illuminate\Http\Request $request
  1051. * @param int $id
  1052. * @return \Illuminate\Http\Response
  1053. */
  1054. public function update(Request $request, $id)
  1055. {
  1056. //
  1057. }
  1058. public function updateStatusPaymentViaDashboard(Request $request)
  1059. {
  1060. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  1061. $staff = StaffDetail::find($request->current_id);
  1062. if(!empty($compound) && !empty($staff)){
  1063. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  1064. if($compound->status != $request->status){
  1065. $compound->status = $request->status;
  1066. $compound->catatan_dari_admin = $request->remark;
  1067. $compound->amount_payment = $request->amount;
  1068. $compound->update_by = $request->current_id;
  1069. $saved = $compound->save();
  1070. if($saved){
  1071. $gDate = $compound->created_at->format('F Y');
  1072. $historyData = [
  1073. 'tarikh_kumpulan' => $gDate,
  1074. ];
  1075. $subHistory = [
  1076. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1077. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1078. '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>",
  1079. ];
  1080. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1081. if(!empty($groupByDate)){
  1082. $groupByDate->subhistory()->create($subHistory);
  1083. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1084. }else{
  1085. $history = History::create($historyData);
  1086. $history->subhistory()->create($subHistory);
  1087. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1088. }
  1089. if($request->status == "Berbayar"){
  1090. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1091. }else{
  1092. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1093. }
  1094. }else{
  1095. $response = [
  1096. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1097. ];
  1098. return response()->json($response, 200);
  1099. }
  1100. }else{
  1101. if($request->remark != ''){
  1102. $compound->catatan_dari_admin = $request->remark;
  1103. $compound->update_by = $request->current_id;
  1104. $compound->save();
  1105. $saved = $compound->save();
  1106. if($saved){
  1107. $gDate = $compound->created_at->format('F Y');
  1108. $historyData = [
  1109. 'tarikh_kumpulan' => $gDate,
  1110. ];
  1111. $subHistory = [
  1112. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1113. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1114. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1115. ];
  1116. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1117. if(!empty($groupByDate)){
  1118. $groupByDate->subhistory()->create($subHistory);
  1119. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1120. }else{
  1121. $history = History::create($historyData);
  1122. $history->subhistory()->create($subHistory);
  1123. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1124. }
  1125. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1126. }else{
  1127. $response = [
  1128. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1129. ];
  1130. return response()->json($response, 200);
  1131. }
  1132. }else{
  1133. $response = [
  1134. 'success' => false, 'message' => 'Tiada kemaskini!',
  1135. ];
  1136. return response()->json($response, 200);
  1137. }
  1138. }
  1139. }else{
  1140. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  1141. $compound->status = $request->status;
  1142. $compound->catatan_dari_admin = $request->remark;
  1143. $compound->amount_payment = $request->amount;
  1144. $compound->update_by = $request->current_id;
  1145. $saved = $compound->save();
  1146. if($saved){
  1147. $gDate = $compound->created_at->format('F Y');
  1148. $historyData = [
  1149. 'tarikh_kumpulan' => $gDate,
  1150. ];
  1151. $subHistory = [
  1152. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1153. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  1154. '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>",
  1155. ];
  1156. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1157. if(!empty($groupByDate)){
  1158. $groupByDate->subhistory()->create($subHistory);
  1159. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1160. }else{
  1161. $history = History::create($historyData);
  1162. $history->subhistory()->create($subHistory);
  1163. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1164. }
  1165. if($request->status == "Berbayar"){
  1166. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  1167. }else{
  1168. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  1169. }
  1170. }else{
  1171. $response = [
  1172. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1173. ];
  1174. return response()->json($response, 200);
  1175. }
  1176. }else{
  1177. if($request->remark != ''){
  1178. $compound->catatan_dari_admin = $request->remark;
  1179. $compound->update_by = $request->current_id;
  1180. $compound->save();
  1181. $saved = $compound->save();
  1182. if($saved){
  1183. $gDate = $compound->created_at->format('F Y');
  1184. $historyData = [
  1185. 'tarikh_kumpulan' => $gDate,
  1186. ];
  1187. $subHistory = [
  1188. 'no_siri' => $compound->ConfidentialFile->no_siri,
  1189. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  1190. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  1191. ];
  1192. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  1193. if(!empty($groupByDate)){
  1194. $groupByDate->subhistory()->create($subHistory);
  1195. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  1196. }else{
  1197. $history = History::create($historyData);
  1198. $history->subhistory()->create($subHistory);
  1199. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  1200. }
  1201. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  1202. }else{
  1203. $response = [
  1204. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  1205. ];
  1206. return response()->json($response, 200);
  1207. }
  1208. }else{
  1209. $response = [
  1210. 'success' => false, 'message' => 'Tiada kemaskini!',
  1211. ];
  1212. return response()->json($response, 200);
  1213. }
  1214. }
  1215. }
  1216. }else{
  1217. $response = [
  1218. 'success' => false,
  1219. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  1220. ];
  1221. return response()->json($response, 200);
  1222. }
  1223. }
  1224. /**
  1225. * Remove the specified resource from storage.
  1226. *
  1227. * @param int $id
  1228. * @return \Illuminate\Http\Response
  1229. */
  1230. public function destroy($id)
  1231. {
  1232. //
  1233. }
  1234. }