Dashboard sipadu mbip
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. <?php
  2. namespace App\Http\Controllers\Main;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use LynX39\LaraPdfMerger\Facades\PdfMerger;
  7. use Carbon\Carbon;
  8. use Validator;
  9. use PDF;
  10. use File;
  11. use App\SiteSetting;
  12. use App\Model\Staff;
  13. use App\Model\StaffDetail;
  14. use App\Model\Module\Department;
  15. use App\Model\Module\Roles;
  16. use App\Model\Module\TemplateNotice;
  17. use App\Model\Module\LetterNotice;
  18. use App\Model\Module\Attachment;
  19. use App\Model\Module\Faulty;
  20. use App\Model\Module\Memo;
  21. use App\Model\Module\Compound;
  22. use App\Model\Module\ConfidentialFile;
  23. use App\Model\Module\History;
  24. use App\Model\Module\SubHistory;
  25. use App\Model\Module\ApiKey;
  26. use App\Model\Module\ApiIntegration;
  27. use App\Jobs\UpdateCompoundPrice;
  28. class SettingController extends Controller
  29. {
  30. /**
  31. * Create a memo list controller.
  32. *
  33. * @return json
  34. */
  35. public function memoIndex(){
  36. $id = Auth::guard('sadmin')->id();
  37. $user = Staff::with('StaffDetail')->find($id);
  38. $site = SiteSetting::first();
  39. return view('main-dashboard.setting.memo_index',compact('user','site'));
  40. }
  41. public function memoAdd(){
  42. $id = Auth::guard('sadmin')->id();
  43. $user = Staff::with('StaffDetail')->find($id);
  44. $department = Department::all();
  45. $roles = Roles::all();
  46. $site = SiteSetting::first();
  47. return view('main-dashboard.setting.memo_detail_add',compact('user','department','roles','site'));
  48. }
  49. public function requestAddMemo(Request $request) {
  50. $id = Auth::guard('sadmin')->id();
  51. $user = Staff::with('StaffDetail')->find($id);
  52. $validator = Validator::make($request->all(), [
  53. 'tawaran' => ['required','regex:/^100+%$|[0-9]+%/'],
  54. 'attachment.*' => 'mimes:pdf|max:2048',
  55. ]);
  56. if ($validator->fails()) {
  57. return redirect()->back()->withInput()->withErrors($validator);
  58. }
  59. $kesalahan = $request->get('kesalahan');
  60. if(!empty($kesalahan)){
  61. $sahkan = '';
  62. if($user->StaffDetail->roles_access == "Ketua Jabatan"){
  63. $sahkan = $user->_id;
  64. }
  65. $faulty = Faulty::where('itkod', $request->get('kesalahan'))->first();
  66. if(!empty($faulty)){
  67. if($request->hasfile('attachment')){
  68. $memo = Memo::create([
  69. 'itkod' => $request->get('kesalahan'),
  70. 'modul' => $request->get('kategori_modul'),
  71. 'jenis_memo' => $request->get('jenis_memo'),
  72. 'no_rujukan' => $request->get('no_rujukan'),
  73. 'tawaran_kompaun' => $request->get('tawaran'),
  74. 'tarikh_mula' => $request->get('tarikh_mula'),
  75. 'tarikh_akhir' => $request->get('tarikh_akhir'),
  76. 'dikeluarkan' => $user->_id,
  77. 'disahkan' => $sahkan,
  78. 'jenis_data' => 'pdf',
  79. 'subjek' => $request->get('subjek'),
  80. 'penerangan' => $request->get('penerangan'),
  81. ]);
  82. $upload = [];
  83. foreach($request->file('attachment') as $f){
  84. $upload[] = [
  85. 'name' => 'file[]',
  86. 'contents' => fopen( $f->getPathname(), 'r' ),
  87. 'filename' => $f->getClientOriginalName()
  88. ];
  89. }
  90. $upload [] = [
  91. 'name' => 'type',
  92. 'contents' => 'mbip'
  93. ];
  94. $client = new \GuzzleHttp\Client();
  95. $result = $client->request('POST', 'https://files.sipadu.my/api/upload/memo/pdf', [
  96. 'multipart' => $upload
  97. ]);
  98. $response = json_decode($result->getBody()->getContents());
  99. if($response->success == true){
  100. foreach ($response->data as $key => $d) {
  101. $attach = new Attachment();
  102. $attach->path = $d;
  103. $memo->attachment()->save($attach);
  104. }
  105. }else if($response->success == false){
  106. return redirect()->back()->with('error_msg', '<strong>Gagal!</strong> memuatnaik pdf');
  107. }
  108. if($sahkan != ''){
  109. $kpd = 'null';
  110. $this->dispatch(new UpdateCompoundPrice($kpd));
  111. }
  112. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> Simpan rekod memo di kategori akta kesalahan <strong>('.$faulty->nama.')</strong>');
  113. }else{
  114. $memo = Memo::create([
  115. 'itkod' => $request->get('kesalahan'),
  116. 'modul' => $request->get('kategori_modul'),
  117. 'jenis_memo' => $request->get('jenis_memo'),
  118. 'no_rujukan' => $request->get('no_rujukan'),
  119. 'tawaran_kompaun' => $request->get('tawaran'),
  120. 'tarikh_mula' => $request->get('tarikh_mula'),
  121. 'tarikh_akhir' => $request->get('tarikh_akhir'),
  122. 'dikeluarkan' => $user->_id,
  123. 'disahkan' => $sahkan,
  124. 'jenis_data' => 'manual',
  125. 'subjek' => $request->get('subjek'),
  126. 'penerangan' => $request->get('penerangan'),
  127. ]);
  128. if($sahkan != ''){
  129. $kpd = 'null';
  130. $this->dispatch(new UpdateCompoundPrice($kpd));
  131. }
  132. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> Simpan rekod memo di kategori akta kesalahan <strong>('.$faulty->nama.')</strong>');
  133. }
  134. }else{
  135. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya Simpan Rekod!</strong> Rekod Akta Kesalahan <b>'.$request->get('kesalahan').'</b> tidak ditemui');
  136. }
  137. }else {
  138. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya Simpan Rekod!</strong> Pastikan anda pilih ketegori/akta kesalahan untuk memo berjalan dengan lancar');
  139. }
  140. }
  141. public function memoEdit($_id){
  142. $id = Auth::guard('sadmin')->id();
  143. $user = Staff::with('StaffDetail')->find($id);
  144. $department = Department::all();
  145. $roles = Roles::all();
  146. $memo = Memo::where('_id',$_id)->first();
  147. $faulty = Faulty::where('itkod',$memo->itkod)->first();
  148. $site = SiteSetting::first();
  149. return view('main-dashboard.setting.memo_detail_edit',compact('user','department','roles','memo','faulty','site'));
  150. }
  151. public function requestEditMemo(Request $request) {
  152. $id = Auth::guard('sadmin')->id();
  153. $user = Staff::with('StaffDetail')->find($id);
  154. $validator = Validator::make($request->all(), [
  155. 'tawaran' => ['required','regex:/^100+%$|[0-9]+%/'],
  156. 'attachment.*' => 'mimes:pdf|max:2048',
  157. ]);
  158. if ($validator->fails()) {
  159. return redirect()->back()->withInput()->withErrors($validator);
  160. }
  161. $sahkan = '';
  162. if($user->StaffDetail->roles_access == "Ketua Jabatan"){
  163. $sahkan = $user->_id;
  164. }
  165. $memo = Memo::with('Attachment')->where('_id',$request->memo_id)->first();
  166. $now = Carbon::now();
  167. $gDate = $now->format('F Y');
  168. if(!empty($memo)){
  169. $faulty = Faulty::where('itkod', $memo->itkod)->first();
  170. if(!empty($faulty)){
  171. if($request->hasfile('attachment')){
  172. $uploadNew = false;
  173. if($memo->jenis_data == "pdf"){
  174. foreach ($memo->Attachment as $m) {
  175. $m->delete();
  176. }
  177. $uploadNew = true;
  178. }else if($memo->jenis_data == "manual"){
  179. $uploadNew = true;
  180. }
  181. if($uploadNew == true){
  182. $memo->jenis_memo = $request->get('jenis_memo');
  183. $memo->no_rujukan = $request->get('no_rujukan');
  184. $memo->tawaran_kompaun = $request->get('tawaran');
  185. $memo->tarikh_mula = $request->get('tarikh_mula');
  186. $memo->tarikh_akhir = $request->get('tarikh_akhir');
  187. $memo->dikeluarkan = $user->_id;
  188. $memo->jenis_data = 'pdf';
  189. $memo->subjek = $request->get('subjek');
  190. $memo->penerangan = $request->get('penerangan');
  191. $memo->save();
  192. $upload = [];
  193. foreach($request->file('attachment') as $f){
  194. $upload[] = [
  195. 'name' => 'file[]',
  196. 'contents' => fopen( $f->getPathname(), 'r' ),
  197. 'filename' => $f->getClientOriginalName()
  198. ];
  199. }
  200. $upload [] = [
  201. 'name' => 'type',
  202. 'contents' => 'mbip'
  203. ];
  204. $client = new \GuzzleHttp\Client();
  205. $result = $client->request('POST', 'https://files.sipadu.my/api/upload/memo/pdf', [
  206. 'multipart' => $upload
  207. ]);
  208. $response = json_decode($result->getBody()->getContents());
  209. if($response->success == true){
  210. foreach ($response->data as $key => $d) {
  211. $attach = new Attachment();
  212. $attach->path = $d;
  213. $memo->attachment()->save($attach);
  214. }
  215. }else if($response->success == false){
  216. return redirect()->back()->with('error_msg', '<strong>Gagal!</strong> memuatnaik pdf');
  217. }
  218. $compound = Compound::with('ConfidentialFile')->where('seksyen_kesalahan', $memo->itkod)->get();
  219. $faulty = Faulty::where('itkod', $memo->itkod )->first();
  220. if(count($compound) > 0){
  221. $historyData = [
  222. 'tarikh_kumpulan' => $gDate,
  223. ];
  224. foreach($compound as $c){
  225. $subHistory = [
  226. 'no_siri' => $c->ConfidentialFile->no_siri,
  227. 'tajuk' => "Kemaskini Memo[ ".$memo->no_rujukan." ] : ".$memo->subjek,
  228. 'huraian' => "Memo ini telah dikemaskini oleh ".$user->roles_access." <a href='".url('/main/staff')."/".$user->_id."/profile'>".$user->StaffDetail->full_name."</a>.",
  229. ];
  230. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  231. if(!empty($groupByDate)){
  232. $groupByDate->subhistory()->create($subHistory);
  233. $c->ConfidentialFile->history()->attach($groupByDate);
  234. }else{
  235. $history = History::create($historyData);
  236. $history->subhistory()->create($subHistory);
  237. $c->ConfidentialFile->history()->attach($history);
  238. }
  239. }
  240. }
  241. if($memo->disahkan != ''){
  242. $kpd = 'null';
  243. $this->dispatch(new UpdateCompoundPrice($kpd));
  244. }
  245. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> Kemaskini rekod memo di kategori akta kesalahan <strong>('.$faulty->nama.')</strong>');
  246. }
  247. }else{
  248. $uploadNew = false;
  249. if($memo->jenis_data == "pdf"){
  250. foreach ($memo->Attachment as $m) {
  251. $m->delete();
  252. }
  253. $uploadNew = true;
  254. }else if($memo->jenis_data == "manual"){
  255. $uploadNew = true;
  256. }
  257. if($uploadNew == true){
  258. $memo->jenis_memo = $request->get('jenis_memo');
  259. $memo->no_rujukan = $request->get('no_rujukan');
  260. $memo->tawaran_kompaun = $request->get('tawaran');
  261. $memo->tarikh_mula = $request->get('tarikh_mula');
  262. $memo->tarikh_akhir = $request->get('tarikh_akhir');
  263. $memo->dikeluarkan = $user->_id;
  264. $memo->jenis_data = 'manual';
  265. $memo->subjek = $request->get('subjek');
  266. $memo->penerangan = $request->get('penerangan');
  267. $memo->save();
  268. $compound = Compound::with('ConfidentialFile')->where('seksyen_kesalahan', $memo->itkod)->get();
  269. $faulty = Faulty::where('itkod', $memo->itkod )->first();
  270. if(count($compound) > 0){
  271. $historyData = [
  272. 'tarikh_kumpulan' => $gDate,
  273. ];
  274. foreach($compound as $c){
  275. $subHistory = [
  276. 'no_siri' => $c->ConfidentialFile->no_siri,
  277. 'tajuk' => "Kemaskini Memo[ ".$memo->no_rujukan." ] : ".$memo->subjek,
  278. 'huraian' => "Memo ini telah dikemaskini oleh ".$user->roles_access." <a href='".url('/main/staff')."/".$user->_id."/profile'>".$user->StaffDetail->full_name."</a>.",
  279. ];
  280. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  281. if(!empty($groupByDate)){
  282. $groupByDate->subhistory()->create($subHistory);
  283. $c->ConfidentialFile->history()->attach($groupByDate);
  284. }else{
  285. $history = History::create($historyData);
  286. $history->subhistory()->create($subHistory);
  287. $c->ConfidentialFile->history()->attach($history);
  288. }
  289. }
  290. }
  291. if($memo->disahkan != ''){
  292. $kpd = 'null';
  293. $this->dispatch(new UpdateCompoundPrice($kpd));
  294. }
  295. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> Kemaskini rekod memo di kategori akta kesalahan <strong>('.$faulty->nama.')</strong>');
  296. }
  297. }
  298. }else{
  299. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya Kemaskini Rekod!</strong> Rekod Akta Kesalahan <b>'.$request->get('kesalahan').'</b> tidak ditemui');
  300. }
  301. }else{
  302. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya Kemaskini Rekod!</strong> Rekod memo tidak ditemui');
  303. }
  304. }
  305. public function requestViewMemoPdf($_id) {
  306. $site = SiteSetting::first();
  307. $memo = Memo::with('Attachment')->where('_id',$_id)->first();
  308. $staffD = Staff::with('StaffDetail')->where('_id',$memo->dikeluarkan)->first();
  309. $staffS = Staff::with('StaffDetail')->where('_id',$memo->disahkan)->first();
  310. $kesalahan = Faulty::where('itkod', $memo->itkod)->first();
  311. $dikeluarkan = ''; $disahkan = ''; $faulty = ''; $modul = '';
  312. if(!empty($staffD)){
  313. $dikeluarkan = $staffD->StaffDetail->full_name;
  314. }
  315. if(!empty($staffS)){
  316. $disahkan = $staffD->StaffDetail->full_name;
  317. }
  318. if(!empty($kesalahan)){
  319. $faulty ='['.$kesalahan->itkod.'] '.$kesalahan->nama;
  320. }
  321. if($memo->modul != '-'){
  322. $r = Roles::where('kod',$memo->modul)->first();
  323. if(!empty($r)){
  324. $modul = $r->name;
  325. }
  326. }
  327. $update = Carbon::parse($memo->updated)->toDateTimeString();
  328. $mula = date('d/m/Y h:i a', strtotime($memo->tarikh_mula));
  329. $akhir = date('d/m/Y', strtotime($memo->tarikh_akhir));
  330. $pdf = PDF::loadView('pdf.memo', compact('memo','dikeluarkan','disahkan','update','mula','akhir','faulty','modul','site'));
  331. $pdf->setPaper('A4', 'potrait');
  332. $destinationPath = 'document/memo';
  333. if(!File::exists(public_path().'/'.$destinationPath)) {
  334. File::makeDirectory(public_path().'/'.$destinationPath, $mode = 0777, true, true);
  335. }
  336. if($memo->jenis_data == "manual"){
  337. return $pdf->stream();
  338. }else if($memo->jenis_data == "pdf"){
  339. $pdf->save(public_path().'/'.$destinationPath.'/'.$memo->_id.'.pdf');
  340. $availablePDF[] = public_path().'/'.$destinationPath.'/'.$memo->_id.'.pdf';
  341. $merges = PDFMerger::init();
  342. foreach($memo->Attachment as $key => $a){
  343. $temp = file_put_contents(public_path().'/'.$destinationPath.'/temp-'.$memo->_id.'-'.$key.'.pdf', fopen($a->path, 'r'));
  344. $availablePDF[] = public_path().'/'.$destinationPath.'/temp-'.$memo->_id.'-'.$key.'.pdf';
  345. }
  346. foreach($availablePDF as $a){
  347. $merges->addPDF($a, 'all');
  348. }
  349. $merges->merge();
  350. foreach($availablePDF as $i => $in){
  351. File::delete($in);
  352. }
  353. File::deleteDirectory(public_path().'/'.$destinationPath);
  354. $merges->save(public_path().'/'.$destinationPath.'/'.$memo->_id.'.pdf',"browser");
  355. }
  356. }
  357. /**
  358. * Create a memo list controller.
  359. *
  360. * @return json
  361. */
  362. public function noticeIndex(){
  363. $id = Auth::guard('sadmin')->id();
  364. $user = Staff::with('StaffDetail')->find($id);
  365. $site = SiteSetting::first();
  366. return view('main-dashboard.setting.template_notice_index', compact('user','site'));
  367. }
  368. public function viewNoticeAdd(){
  369. $id = Auth::guard('sadmin')->id();
  370. $user = Staff::with('StaffDetail')->find($id);
  371. $department = Department::all();
  372. $site = SiteSetting::first();
  373. return view('main-dashboard.setting.template_notice_add',compact('user', 'department','site'));
  374. }
  375. public function viewNoticeEdit($_id){
  376. $id = Auth::guard('sadmin')->id();
  377. $user = Staff::with('StaffDetail')->find($id);
  378. $department = Department::all();
  379. $template = TemplateNotice::with('Attachment')->where('_id',$_id)->first();
  380. $de = Department::where('_id', $template->department_id)->first();
  381. $seksyen = Faulty::where('jbkod', $de->jbkod)->where('akkod', $template->akta_kesalahan)->get();
  382. return view('main-dashboard.setting.template_notice_edit',compact('user','template','department','seksyen'));
  383. }
  384. public function addTemplateNotice(Request $request){
  385. $id = Auth::guard('sadmin')->id();
  386. $user = Staff::with('StaffDetail')->find($id);
  387. $validator = Validator::make($request->all(), [
  388. 'attachment' => 'mimes:jpeg,jpg|max:2048',
  389. ]);
  390. if ($validator->fails()) {
  391. return redirect()->back()->withInput()->withErrors($validator);
  392. }
  393. $dataTemplate = [
  394. 'akta_kesalahan' => $request->acts,
  395. 'seksyen_kesalahan' => $request->seksyen,
  396. 'jenis_amaran' => $request->jenis_amaran,
  397. 'tempoh_hantar' => $request->tempoh,
  398. 'no_rujukan' => $request->no_rujukan,
  399. 'subjek' => $request->subjek,
  400. 'kandungan' => $request->kandungan,
  401. // 'nama_pengirim' => $request->nama_pengirim,
  402. // 'jawatan_pengirim' => $request->jawatan_pengirim,
  403. 'status' => 'tidak aktif'
  404. ];
  405. $department = Department::where('jbkod', $request->department)->first();
  406. if(!empty($department)){
  407. $template = TemplateNotice::create($dataTemplate);
  408. $department->templatenotice()->save($template);
  409. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> Simpan rekod templat notis amaran');
  410. }else{
  411. return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> Simpan rekod templat notis amaran');
  412. }
  413. // if($request->hasfile('attachment')){
  414. // $destinationPath = 'document/notis-amaran';
  415. // $uploaded = public_path().'/'.$destinationPath;
  416. // $allowedfileExtension = ['jpg','jpeg'];
  417. // $a = $request->file('attachment');
  418. // $extension = $a->getClientOriginalExtension();
  419. // $check=in_array($extension,$allowedfileExtension);
  420. // if($check) {
  421. // $filename = $template->_id;
  422. // $a->move($destinationPath, $filename.'.'.$extension);
  423. // $pathImage = '/'.$destinationPath.'/'.$filename.'.'.$extension;
  424. // $attach = new Attachment();
  425. // $attach->path = $pathImage;
  426. // $template->attachment()->save($attach);
  427. // }
  428. // }else{
  429. // return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> Simpan rekod templat notis amaran');
  430. // }
  431. }
  432. public function editTemplateNotice(Request $request){
  433. $id = Auth::guard('sadmin')->id();
  434. $user = Staff::with('StaffDetail')->find($id);
  435. $validator = Validator::make($request->all(), [
  436. 'attachment' => 'mimes:jpeg,jpg|max:2048',
  437. ]);
  438. if ($validator->fails()) {
  439. return redirect()->back()->withInput()->withErrors($validator);
  440. }
  441. $template = TemplateNotice::where('_id',$request->_id)->first();
  442. if(!empty($template)){
  443. $department = Department::where('jbkod', $request->department)->first();
  444. if(!empty($department)){
  445. $template->department_id = $department->_id;
  446. $template->akta_kesalahan = $request->acts;
  447. $template->seksyen_kesalahan = $request->seksyen;
  448. $template->jenis_amaran = $request->jenis_amaran;
  449. $template->tempoh_hantar = $request->tempoh;
  450. $template->no_rujukan = $request->no_rujukan;
  451. $template->subjek = $request->subjek;
  452. $template->kandungan = $request->kandungan;
  453. $template->status = 'tidak aktif';
  454. $template->save();
  455. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> Kemaskini rekod templat notis amaran. Anda boleh "aktifkan" notis amaran ini di "Senarai Templat Notis Amaran"');
  456. }else{
  457. return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> rekod jabatan tidak ditemui');
  458. }
  459. }else{
  460. return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> rekod templat notis amaran tidak ditemui');
  461. }
  462. }
  463. public function viewLetterPDF($_id,$kpd){
  464. $compound = Compound::where('kpd',$kpd)->first();
  465. $site = SiteSetting::first();
  466. $template = TemplateNotice::where('_id',$_id)->first();
  467. if(!empty($template)){
  468. $now = Carbon::now()->format('d/m/Y h:i:s A');
  469. $pdf = PDF::loadView('pdf.template_letter', compact('template','now','compound','site'));
  470. $pdf->setPaper('A4', 'potrait');
  471. return $pdf->stream();
  472. }else{
  473. $template = LetterNotice::with('Attachment')->where('_id',$_id)->first();
  474. if(!empty($template)){
  475. $now = Carbon::now()->format('d/m/Y h:i:s A');
  476. $pdf = PDF::loadView('pdf.template_letter', compact('template','now','compound','site'));
  477. $pdf->setPaper('A4', 'potrait');
  478. return $pdf->stream();
  479. }
  480. }
  481. }
  482. public function updatePosNumber(Request $request){
  483. $letter = LetterNotice::where('_id',$request->letter_id)->first();
  484. if(!empty($letter)){
  485. $compound = Compound::with('ConfidentialFile')->where('_id', $letter->compound_id)->first();
  486. if($request->hasFile('gambar_pos')){
  487. $validator = Validator::make($request->all(), [
  488. 'gambar_pos' => 'mimes:jpg,jpeg',
  489. ]);
  490. if ($validator->fails()) {
  491. return redirect()->back()->withInput()->withErrors($validator);
  492. }
  493. $path = '';
  494. $destinationPath = 'document/'.$compound->ConfidentialFile->no_siri.'/notice';
  495. $a = $request->file('gambar_pos');
  496. $extension = $a->getClientOriginalExtension();
  497. $filename = 'pos_notice_'.$letter->_id;
  498. $a->move($destinationPath,$filename.'.'.$extension);
  499. $path = $destinationPath.'/'.$filename.'.'.$extension;
  500. $letter->no_pos = $request->no_pos;
  501. $letter->save();
  502. $attach = new Attachment();
  503. $attach->path = $path;
  504. $letter->attachment()->save($attach);
  505. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> simpan nombor pos');
  506. }else{
  507. return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> sila masukkan gamabr pos sekali');
  508. }
  509. }else{
  510. return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> rekod surat notis amaran tidak ditemui');
  511. }
  512. }
  513. /**
  514. * Laman web controller.
  515. *
  516. * @return json
  517. */
  518. public function generalSetting(){
  519. $id = Auth::guard('sadmin')->id();
  520. $user = Staff::with('StaffDetail')->find($id);
  521. $site = SiteSetting::first();
  522. return view('main-dashboard.setting.general_setting', compact('user','site'));
  523. }
  524. public function letterSetting(){
  525. $id = Auth::guard('sadmin')->id();
  526. $user = Staff::with('StaffDetail')->find($id);
  527. $site = SiteSetting::first();
  528. return view('main-dashboard.setting.letter_setting', compact('user','site'));
  529. }
  530. public function compoundSetting(){
  531. $id = Auth::guard('sadmin')->id();
  532. $user = Staff::with('StaffDetail')->find($id);
  533. $site = SiteSetting::first();
  534. return view('main-dashboard.setting.compound_setting', compact('user','site'));
  535. }
  536. public function updateSettingVariables(Request $request){
  537. $site = SiteSetting::first();
  538. if($request->umum == "true"){
  539. $site->site_title = $request->site_title;
  540. $site->site_tagline = $request->site_tagline;
  541. $site->save();
  542. if($request->hasFile('favicon')){
  543. $path = '';
  544. $validator = Validator::make($request->all(), [
  545. 'favicon' => 'mimes:png|dimensions:width=32,height=32',
  546. ]);
  547. if ($validator->fails()) {
  548. return redirect()->back()->withInput()->withErrors($validator);
  549. }
  550. $destinationPath = 'uploads';
  551. $a = $request->file('favicon');
  552. $extension = $a->getClientOriginalExtension();
  553. $filename = 'favicon';
  554. $a->move($destinationPath,$filename.'.'.$extension);
  555. $path = $destinationPath.'/'.$filename.'.'.$extension;
  556. $site->favicon = $path;
  557. $site->save();
  558. }
  559. if($request->hasFile('logo')){
  560. $path = '';
  561. $validator = Validator::make($request->all(), [
  562. 'logo' => 'mimes:png|dimensions:width=614,height=167',
  563. ]);
  564. if ($validator->fails()) {
  565. return redirect()->back()->withInput()->withErrors($validator);
  566. }
  567. $destinationPath = 'uploads';
  568. $a = $request->file('logo');
  569. $extension = $a->getClientOriginalExtension();
  570. $filename = 'logo';
  571. $a->move($destinationPath,$filename.'.'.$extension);
  572. $path = $destinationPath.'/'.$filename.'.'.$extension;
  573. $site->logo = $path;
  574. $site->save();
  575. }
  576. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> simpan perubahan');
  577. }
  578. if($request->letter == "true"){
  579. $site->building_name = $request->building_name;
  580. $site->address = $request->address;
  581. $site->state_code = $request->postcode;
  582. $site->no_tel = $request->no_tel;
  583. $site->no_fax = $request->no_faks;
  584. $site->email = $request->email;
  585. $site->save();
  586. if($request->hasFile('letter_head')){
  587. $path = '';
  588. $validator = Validator::make($request->all(), [
  589. 'letter_head' => 'mimes:png|dimensions:max_width=700,max_height=109',
  590. ]);
  591. if ($validator->fails()) {
  592. return redirect()->back()->withInput()->withErrors($validator);
  593. }
  594. $destinationPath = 'uploads';
  595. $a = $request->file('letter_head');
  596. $extension = $a->getClientOriginalExtension();
  597. $filename = 'letter_head';
  598. $a->move($destinationPath,$filename.'.'.$extension);
  599. $path = $destinationPath.'/'.$filename.'.'.$extension;
  600. $site->letter_head = $path;
  601. $site->save();
  602. }
  603. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> simpan perubahan');
  604. }
  605. if($request->compound == "true"){
  606. if($request->hasFile('bg_compound')){
  607. $path = '';
  608. $validator = Validator::make($request->all(), [
  609. 'bg_compound' => 'mimes:png|dimensions:width=450,height=450',
  610. ]);
  611. if ($validator->fails()) {
  612. return redirect()->back()->withInput()->withErrors($validator);
  613. }
  614. $destinationPath = 'uploads';
  615. $a = $request->file('bg_compound');
  616. $extension = $a->getClientOriginalExtension();
  617. $filename = 'bg_compound';
  618. $a->move($destinationPath,$filename.'.'.$extension);
  619. $path = $destinationPath.'/'.$filename.'.'.$extension;
  620. $site->bg_compound = $path;
  621. $site->save();
  622. }
  623. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> simpan perubahan');
  624. }
  625. }
  626. /**
  627. * Api Integration controller.
  628. *
  629. * @return json
  630. */
  631. public function viewApiKey(){
  632. $id = Auth::guard('sadmin')->id();
  633. $user = Staff::with('StaffDetail')->find($id);
  634. $site = SiteSetting::first();
  635. return view('main-dashboard.api.view_api_key', compact('user','site'));
  636. }
  637. public function viewApiIntegration(){
  638. $id = Auth::guard('sadmin')->id();
  639. $user = Staff::with('StaffDetail')->find($id);
  640. $site = SiteSetting::first();
  641. $api = ApiKey::all();
  642. return view('main-dashboard.api.view_api_integration_index', compact('user','site','api'));
  643. }
  644. public function addApiKey(Request $request){
  645. $id = Auth::guard('sadmin')->id();
  646. $user = Staff::with('StaffDetail')->find($id);
  647. $scopes = array();
  648. if($request->has('compound_search')){
  649. array_push($scopes, 'compound.search');
  650. }
  651. if($request->has('compound_update')){
  652. array_push($scopes, 'compound.update.status');
  653. }
  654. do {
  655. $api_key = str_random(7);
  656. } while (ApiKey::where("key_prefix", "=", $api_key)->first() instanceof Api);
  657. $data = [
  658. 'name' => $request->name,
  659. 'key_prefix' => $api_key,
  660. 'scopes' => $scopes
  661. ];
  662. $api = ApiKey::create($data);
  663. return redirect()->back()->with('success_msg', 'Successfully store new Api Key');
  664. }
  665. public function addIntegrasi(Request $request){
  666. $id = Auth::guard('sadmin')->id();
  667. $user = Staff::with('StaffDetail')->find($id);
  668. $api = ApiKey::where('_id',$request->type_api)->first();
  669. if(!empty($api)){
  670. $api_key = $api->key_prefix.'.'.str_random(32);
  671. $data = [
  672. 'client' => $request->client,
  673. 'key' => $api_key,
  674. 'status' => 'active'
  675. ];
  676. $apiI = $api->apiintegrasi()->create($data);
  677. return redirect()->back()->with('success_msg', 'Successfully store clients');
  678. }
  679. }
  680. }