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

CompoundResourceController.php 79KB

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