Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SettingController.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <?php
  2. namespace App\Http\Controllers\api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Api\BaseController;
  5. use Config;
  6. use File;
  7. use Carbon\Carbon;
  8. use App\Model\Staff;
  9. use App\Model\StaffDetail;
  10. use App\Model\Module\Roles;
  11. use App\Model\Module\Department;
  12. use App\Model\Module\Faulty;
  13. use App\Model\Module\Memo;
  14. use App\Model\Module\Compound;
  15. use App\Model\Module\ConfidentialFile;
  16. use App\Model\Module\TemplateNotice;
  17. use App\Model\Module\Attachment;
  18. use App\Model\Module\History;
  19. use App\Model\Module\SubHistory;
  20. use App\Model\Module\LetterNotice;
  21. use App\Model\Module\ApiKey;
  22. use App\Model\Module\ApiIntegration;
  23. use App\Jobs\UpdateCompoundPrice;
  24. use App\Jobs\SendNoticeLetter;
  25. class SettingController extends BaseController
  26. {
  27. /**
  28. * Create a memo list controller.
  29. *
  30. * @return json
  31. */
  32. public function memoList(){
  33. $nested_data = array();
  34. $memo = Memo::with('Attachment')->where('modul','-')->orderBy('updated_at', 'desc')->get();
  35. $curr = Carbon::now()->getTimestamp();
  36. $i = 1;
  37. foreach($memo as $a)
  38. {
  39. $n1 = ''; $dikeluarkan = ''; $disahkan = '';
  40. $reg_time = $a->updated_at;
  41. $expiry_date = $reg_time->addDays(3);
  42. $expiry_date = $expiry_date->getTimestamp();
  43. if($curr < $expiry_date) {
  44. $n1 = "Baru/";
  45. }else{
  46. $n1 = "";
  47. }
  48. $staffD = Staff::with('StaffDetail')->where('_id',$a->dikeluarkan)->first();
  49. if(!empty($staffD)){
  50. $dikeluarkan = $staffD->StaffDetail->full_name;
  51. }
  52. $staffS = Staff::with('StaffDetail')->where('_id',$a->disahkan)->first();
  53. if(!empty($staffS)){
  54. $disahkan = $staffD->StaffDetail->full_name;
  55. }
  56. array_push($nested_data, array(
  57. 'index' => $n1.$i,
  58. 'itkod' => $a->itkod,
  59. 'jenis' => $a->jenis_memo,
  60. 'no_rujukan' => $a->no_rujukan,
  61. 'mula' => date('d/m/Y h:i a', strtotime($a->tarikh_mula)),
  62. 'akhir' => date('d/m/Y h:i a', strtotime($a->tarikh_akhir)),
  63. 'dikeluakan' => $dikeluarkan,
  64. 'disahkan' => $disahkan,
  65. 'tindakan' => $a->_id
  66. ));
  67. $i++;
  68. }
  69. return \DataTables::of($nested_data)->make(true);
  70. }
  71. public function deleteMemo(Request $request){
  72. $staff = Staff::with('StaffDetail')->where('_id',$request->staff)->first();
  73. $memo = Memo::with('Attachment')->where('_id',$request->id)->first();
  74. if(!empty($memo)){
  75. if($memo->jenis_data == "pdf"){
  76. $memo->attachment()->delete();
  77. $memo->delete();
  78. $compound = Compound::with('ConfidentialFile')->where('seksyen_kesalahan', $memo->itkod)->get();
  79. $faulty = Faulty::where('itkod', $memo->itkod )->first();
  80. if(count($compound) > 0){
  81. $now = Carbon::now();
  82. $gDate = $now->format('F Y');
  83. $historyData = [
  84. 'tarikh_kumpulan' => $gDate,
  85. ];
  86. foreach($compound as $c){
  87. $subHistory = [
  88. 'no_siri' => $c->ConfidentialFile->no_siri,
  89. 'tajuk' => $staff->StaffDetail->roles_access." ".$staff->StaffDetail->full_name." mengemaskini memo ".$memo->no_rujukan,
  90. 'huraian' => "Rekod memo (".$memo->no_rujukan.") dikemaskini/di buang oleh ".$staff->StaffDetail->roles_access." <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>.",
  91. ];
  92. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  93. if(!empty($groupByDate)){
  94. $groupByDate->subhistory()->create($subHistory);
  95. $c->ConfidentialFile->history()->attach($groupByDate);
  96. }else{
  97. $history = History::create($historyData);
  98. $history->subhistory()->create($subHistory);
  99. $c->ConfidentialFile->history()->attach($history);
  100. }
  101. }
  102. }
  103. if($memo->disahkan != ''){
  104. $kpd = 'null';
  105. $this->dispatch(new UpdateCompoundPrice($kpd));
  106. }
  107. return response()->json(['status' => 'true', 'desc' => 'Buang rekod memo ( '.$memo->no_rujukan.' )']);
  108. }else if($memo->jenis_data == "manual"){
  109. $memo->delete();
  110. $compound = Compound::with('ConfidentialFile')->where('seksyen_kesalahan', $memo->itkod)->get();
  111. $faulty = Faulty::where('itkod', $memo->itkod )->first();
  112. if(count($compound) > 0){
  113. $now = Carbon::now();
  114. $gDate = $now->format('F Y');
  115. $historyData = [
  116. 'tarikh_kumpulan' => $gDate,
  117. ];
  118. foreach($compound as $c){
  119. $subHistory = [
  120. 'no_siri' => $c->ConfidentialFile->no_siri,
  121. 'tajuk' => $staff->StaffDetail->roles_access." ".$staff->StaffDetail->full_name." mengemaskini memo ".$memo->no_rujukan,
  122. 'huraian' => "Rekod memo (".$memo->no_rujukan.") dikemaskini/di buang oleh ".$staff->StaffDetail->roles_access." <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>.",
  123. ];
  124. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  125. if(!empty($groupByDate)){
  126. $groupByDate->subhistory()->create($subHistory);
  127. $c->ConfidentialFile->history()->attach($groupByDate);
  128. }else{
  129. $history = History::create($historyData);
  130. $history->subhistory()->create($subHistory);
  131. $c->ConfidentialFile->history()->attach($history);
  132. }
  133. }
  134. }
  135. if($memo->disahkan != ''){
  136. $kpd = 'null';
  137. $this->dispatch(new UpdateCompoundPrice($kpd));
  138. }
  139. return response()->json(['status' => 'true', 'desc' => 'Buang rekod memo ( '.$memo->no_rujukan.' )']);
  140. }else{
  141. return response()->json(['status' => 'false', 'desc' => 'Buang rekod memo']);
  142. }
  143. }else{
  144. return response()->json(['status' => 'false', 'desc' => 'Buang rekod memo']);
  145. }
  146. }
  147. public function confirmMemo(Request $request){
  148. $memo = Memo::with('Attachment')->where('_id',$request->id)->first();
  149. if(!empty($memo)){
  150. $staffD = Staff::with('StaffDetail')->where('_id',$request->confirm_id)->first();
  151. if(!empty($staffD)){
  152. $kpd = $request->kpd;
  153. $tajuk = ""; $huraian = "";
  154. if($memo->disahkan == ""){
  155. $memo->disahkan = $staffD->_id;
  156. $memo->save();
  157. $tajuk = "Memo[ ".$memo->no_rujukan." ] : ".$memo->subjek ." telah disahkan oleh ".$staffD->roles_access;
  158. $huraian = "Memo ini telah disahkan oleh ".$staffD->roles_access." <a href='".url('/main/staff')."/".$staffD->_id."/profile'>".$staffD->StaffDetail->full_name."</a> dan telah berkuat kuasa serta merta";
  159. }else{
  160. $memo->disahkan = "";
  161. $memo->save();
  162. $tajuk = "Memo[ ".$memo->no_rujukan." ] : ".$memo->subjek ." tidak disahkan oleh ".$staffD->roles_access;
  163. $huraian = "Memo ini tidak disahkan oleh ".$staffD->roles_access." <a href='".url('/main/staff')."/".$staffD->_id."/profile'>".$staffD->StaffDetail->full_name."</a>.";
  164. }
  165. $this->dispatch(new UpdateCompoundPrice($kpd));
  166. $now = Carbon::now();
  167. $gDate = $now->format('F Y');
  168. $compound = Compound::with('ConfidentialFile')->where('seksyen_kesalahan', $memo->itkod)->get();
  169. $faulty = Faulty::where('itkod', $memo->itkod )->first();
  170. if(!empty($compound)){
  171. $historyData = [
  172. 'tarikh_kumpulan' => $gDate,
  173. ];
  174. foreach($compound as $c){
  175. $subHistory = [
  176. 'no_siri' => $c->ConfidentialFile->no_siri,
  177. 'tajuk' => $tajuk,
  178. 'huraian' => $huraian,
  179. ];
  180. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  181. if(!empty($groupByDate)){
  182. $groupByDate->subhistory()->create($subHistory);
  183. $c->ConfidentialFile->history()->attach($groupByDate);
  184. }else{
  185. $history = History::create($historyData);
  186. $history->subhistory()->create($subHistory);
  187. $c->ConfidentialFile->history()->attach($history);
  188. }
  189. }
  190. return response()->json(['status' => 'true', 'desc' => 'Memo ini telah disahkan dan dikuat kuasakan serta merta']);
  191. }
  192. }else{
  193. return response()->json(['status' => 'false', 'desc' => 'Data kakitangan ( '.$staff->StaffDetail->full_name.' ) ini tidak ditemui']);
  194. }
  195. }else{
  196. return response()->json(['status' => 'false', 'desc' => 'Rekod memo tidak ditemui']);
  197. }
  198. }
  199. /**
  200. * Create template notice list controller.
  201. *
  202. * @return json
  203. */
  204. public function templateList($_id, $status){
  205. $nested_data = array();
  206. $curr = Carbon::now()->getTimestamp();
  207. if($status == 'aktif'){
  208. $compound = Compound::with('LetterNotice')->where('kpd', $_id)->first();
  209. if(!empty($compound->LetterNotice)){
  210. foreach ($compound->LetterNotice as $key => $a) {
  211. $n1 = '';
  212. $reg_time = $a->updated_at;
  213. $expiry_date = $reg_time->addDays(3);
  214. $expiry_date = $expiry_date->getTimestamp();
  215. if($curr < $expiry_date) {
  216. $n1 = "Baru/";
  217. }else{
  218. $n1 = "";
  219. }
  220. array_push($nested_data, array(
  221. 'index' => $n1.$a->jenis_amaran,
  222. 'no_rujukan' => $a->no_rujukan,
  223. 'alasan' => $a->alasan,
  224. 'tindakan1' => $a->no_pos,
  225. 'tindakan2' => $a->_id
  226. ));
  227. }
  228. }
  229. }else{
  230. $template = TemplateNotice::all();
  231. foreach($template as $key => $a) {
  232. $n1 = ''; $aktif = '';
  233. $reg_time = $a->updated_at;
  234. $expiry_date = $reg_time->addDays(3);
  235. $expiry_date = $expiry_date->getTimestamp();
  236. if($curr < $expiry_date) {
  237. $n1 = "Baru/";
  238. }else{
  239. $n1 = "";
  240. }
  241. array_push($nested_data, array(
  242. 'index' => $n1.$a->jenis_amaran,
  243. 'no_rujukan' => $a->no_rujukan,
  244. 'tempoh' => $a->tempoh_hantar,
  245. 'status' => $a->status,
  246. 'tindakan' => $a->_id
  247. ));
  248. }
  249. }
  250. return \DataTables::of($nested_data)->make(true);
  251. }
  252. public function confirmTemplate(Request $request){
  253. $template = TemplateNotice::where('_id',$request->id)->first();
  254. if(!empty($template)){
  255. $template->status = $request->status;
  256. $template->save();
  257. return response()->json(['status' => 'true', 'desc' => 'Status templat notis amaran ini telah "'.$request->status.'"']);
  258. }else{
  259. return response()->json(['status' => 'false', 'desc' => 'Rekod notis amaran tidak ditemui']);
  260. }
  261. }
  262. public function deleteTemplate(Request $request){
  263. $template = TemplateNotice::with('Attachment')->where('_id',$request->id)->first();
  264. if(!empty($template)){
  265. if(!empty($template->Attachment)){
  266. $template->attachment()->delete();
  267. }
  268. $template->delete();
  269. return response()->json(['status' => 'true', 'desc' => 'Buang rekod template notis amaran ( '.$template->no_rujukan.' )']);
  270. }else{
  271. return response()->json(['status' => 'false', 'desc' => 'Buang rekod template notis amaran']);
  272. }
  273. }
  274. public function sendNotice(Request $request){
  275. $template = TemplateNotice::with('Attachment')->where('_id',$request->id)->first();
  276. if(!empty($template)){
  277. return response()->json(['status' => 'true', 'desc' => 'Percubaan Hantar email ( '.$template->no_rujukan.' )']);
  278. }else{
  279. return response()->json(['status' => 'false', 'desc' => 'Buang rekod template notis amaran ( '.$template->no_rujukan.' )']);
  280. }
  281. }
  282. /**
  283. * Create API list controller.
  284. *
  285. * @return json
  286. */
  287. public function apiKeyList(){
  288. $nested_data = array();
  289. $api = ApiKey::orderBy('updated_at', 'desc')->get();
  290. $curr = Carbon::now()->getTimestamp();
  291. $i = 1;
  292. foreach($api as $a)
  293. {
  294. $n1 = '';
  295. $reg_time = $a->updated_at;
  296. $expiry_date = $reg_time->addDays(3);
  297. $expiry_date = $expiry_date->getTimestamp();
  298. if($curr < $expiry_date) {
  299. $n1 = "New/";
  300. }else{
  301. $n1 = "";
  302. }
  303. array_push($nested_data, array(
  304. 'index' => $n1.$a->name,
  305. 'key_prefix' => $a->key_prefix,
  306. 'scopes' => count($a->scopes). ' scopes enabled',
  307. 'action' => $a->_id,
  308. ));
  309. $i++;
  310. }
  311. return \DataTables::of($nested_data)->make(true);
  312. }
  313. public function deleteApiKey(Request $request){
  314. $apiKey = ApiKey::where('_id', $request->id)->first();
  315. if(!empty($apiKey)){
  316. $apiKey->delete();
  317. return response()->json(['status' => 'true', 'desc' => 'Successfully delete Api Key']);
  318. }else{
  319. return response()->json(['status' => 'false', 'desc' => 'Record Api Key not found!']);
  320. }
  321. }
  322. public function apiKeyIntegrationList(){
  323. $nested_data = array();
  324. $curr = Carbon::now()->getTimestamp();
  325. $i = 1;
  326. $api = ApiIntegration::with('ApiKey')->orderBy('created_at', 'desc')->get();
  327. foreach($api as $a)
  328. {
  329. $n1 = '';
  330. $reg_time = $a->created_at;
  331. $expiry_date = $reg_time->addDays(3);
  332. $expiry_date = $expiry_date->getTimestamp();
  333. if($curr < $expiry_date) {
  334. $n1 = "New/";
  335. }else{
  336. $n1 = "";
  337. }
  338. if(!empty($a->ApiKey)){
  339. array_push($nested_data, array(
  340. 'index' => $n1.$a->updated_at->toDateTimeString(),
  341. 'client' => $a->client,
  342. 'api' => $a->ApiKey->scopes,
  343. 'key' => $a->key,
  344. 'status' => $a->status
  345. ));
  346. $i++;
  347. }
  348. }
  349. return \DataTables::of($nested_data)->make(true);
  350. }
  351. }