where('modul','-')->orderBy('updated_at', 'desc')->get(); $curr = Carbon::now()->getTimestamp(); $i = 1; foreach($memo as $a) { $n1 = ''; $dikeluarkan = ''; $disahkan = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "Baru/"; }else{ $n1 = ""; } $staffD = Staff::with('StaffDetail')->where('_id',$a->dikeluarkan)->first(); if(!empty($staffD)){ $dikeluarkan = $staffD->StaffDetail->full_name; } $staffS = Staff::with('StaffDetail')->where('_id',$a->disahkan)->first(); if(!empty($staffS)){ $disahkan = $staffD->StaffDetail->full_name; } array_push($nested_data, array( 'index' => $n1.$i, 'itkod' => $a->itkod, 'jenis' => $a->jenis_memo, 'no_rujukan' => $a->no_rujukan, 'mula' => date('d/m/Y h:i a', strtotime($a->tarikh_mula)), 'akhir' => date('d/m/Y h:i a', strtotime($a->tarikh_akhir)), 'dikeluakan' => $dikeluarkan, 'disahkan' => $disahkan, 'tindakan' => $a->_id )); $i++; } return \DataTables::of($nested_data)->make(true); } public function deleteMemo(Request $request){ $staff = Staff::with('StaffDetail')->where('_id',$request->staff)->first(); $memo = Memo::with('Attachment')->where('_id',$request->id)->first(); if(!empty($memo)){ if($memo->jenis_data == "pdf"){ $memo->attachment()->delete(); $memo->delete(); $compound = Compound::with('ConfidentialFile')->where('seksyen_kesalahan', $memo->itkod)->get(); $faulty = Faulty::where('itkod', $memo->itkod )->first(); if(count($compound) > 0){ $now = Carbon::now(); $gDate = $now->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; foreach($compound as $c){ $subHistory = [ 'no_siri' => $c->ConfidentialFile->no_siri, 'tajuk' => $staff->StaffDetail->roles_access." ".$staff->StaffDetail->full_name." mengemaskini memo ".$memo->no_rujukan, 'huraian' => "Rekod memo (".$memo->no_rujukan.") dikemaskini/di buang oleh ".$staff->StaffDetail->roles_access." _id."/profile'>".$staff->StaffDetail->full_name.".", ]; $groupByDate = History::where('tarikh_kumpulan', $gDate)->first(); if(!empty($groupByDate)){ $groupByDate->subhistory()->create($subHistory); $c->ConfidentialFile->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $c->ConfidentialFile->history()->attach($history); } } } if($memo->disahkan != ''){ $kpd = 'null'; $this->dispatch(new UpdateCompoundPrice($kpd)); } return response()->json(['status' => 'true', 'desc' => 'Buang rekod memo ( '.$memo->no_rujukan.' )']); }else if($memo->jenis_data == "manual"){ $memo->delete(); $compound = Compound::with('ConfidentialFile')->where('seksyen_kesalahan', $memo->itkod)->get(); $faulty = Faulty::where('itkod', $memo->itkod )->first(); if(count($compound) > 0){ $now = Carbon::now(); $gDate = $now->format('F Y'); $historyData = [ 'tarikh_kumpulan' => $gDate, ]; foreach($compound as $c){ $subHistory = [ 'no_siri' => $c->ConfidentialFile->no_siri, 'tajuk' => $staff->StaffDetail->roles_access." ".$staff->StaffDetail->full_name." mengemaskini memo ".$memo->no_rujukan, 'huraian' => "Rekod memo (".$memo->no_rujukan.") dikemaskini/di buang oleh ".$staff->StaffDetail->roles_access." _id."/profile'>".$staff->StaffDetail->full_name.".", ]; $groupByDate = History::where('tarikh_kumpulan', $gDate)->first(); if(!empty($groupByDate)){ $groupByDate->subhistory()->create($subHistory); $c->ConfidentialFile->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $c->ConfidentialFile->history()->attach($history); } } } if($memo->disahkan != ''){ $kpd = 'null'; $this->dispatch(new UpdateCompoundPrice($kpd)); } return response()->json(['status' => 'true', 'desc' => 'Buang rekod memo ( '.$memo->no_rujukan.' )']); }else{ return response()->json(['status' => 'false', 'desc' => 'Buang rekod memo']); } }else{ return response()->json(['status' => 'false', 'desc' => 'Buang rekod memo']); } } public function confirmMemo(Request $request){ $memo = Memo::with('Attachment')->where('_id',$request->id)->first(); if(!empty($memo)){ $staffD = Staff::with('StaffDetail')->where('_id',$request->confirm_id)->first(); if(!empty($staffD)){ $kpd = $request->kpd; $tajuk = ""; $huraian = ""; if($memo->disahkan == ""){ $memo->disahkan = $staffD->_id; $memo->save(); $tajuk = "Memo[ ".$memo->no_rujukan." ] : ".$memo->subjek ." telah disahkan oleh ".$staffD->roles_access; $huraian = "Memo ini telah disahkan oleh ".$staffD->roles_access." _id."/profile'>".$staffD->StaffDetail->full_name." dan telah berkuat kuasa serta merta"; }else{ $memo->disahkan = ""; $memo->save(); $tajuk = "Memo[ ".$memo->no_rujukan." ] : ".$memo->subjek ." tidak disahkan oleh ".$staffD->roles_access; $huraian = "Memo ini tidak disahkan oleh ".$staffD->roles_access." _id."/profile'>".$staffD->StaffDetail->full_name."."; } $this->dispatch(new UpdateCompoundPrice($kpd)); $now = Carbon::now(); $gDate = $now->format('F Y'); $compound = Compound::with('ConfidentialFile')->where('seksyen_kesalahan', $memo->itkod)->get(); $faulty = Faulty::where('itkod', $memo->itkod )->first(); if(!empty($compound)){ $historyData = [ 'tarikh_kumpulan' => $gDate, ]; foreach($compound as $c){ $subHistory = [ 'no_siri' => $c->ConfidentialFile->no_siri, 'tajuk' => $tajuk, 'huraian' => $huraian, ]; $groupByDate = History::where('tarikh_kumpulan', $gDate)->first(); if(!empty($groupByDate)){ $groupByDate->subhistory()->create($subHistory); $c->ConfidentialFile->history()->attach($groupByDate); }else{ $history = History::create($historyData); $history->subhistory()->create($subHistory); $c->ConfidentialFile->history()->attach($history); } } return response()->json(['status' => 'true', 'desc' => 'Memo ini telah disahkan dan dikuat kuasakan serta merta']); } }else{ return response()->json(['status' => 'false', 'desc' => 'Data kakitangan ( '.$staff->StaffDetail->full_name.' ) ini tidak ditemui']); } }else{ return response()->json(['status' => 'false', 'desc' => 'Rekod memo tidak ditemui']); } } /** * Create template notice list controller. * * @return json */ public function templateList($_id, $status){ $nested_data = array(); $curr = Carbon::now()->getTimestamp(); if($status == 'aktif'){ $compound = Compound::with('LetterNotice')->where('kpd', $_id)->first(); if(!empty($compound->LetterNotice)){ foreach ($compound->LetterNotice as $key => $a) { $n1 = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "Baru/"; }else{ $n1 = ""; } array_push($nested_data, array( 'index' => $n1.$a->jenis_amaran, 'no_rujukan' => $a->no_rujukan, 'alasan' => $a->alasan, 'tindakan1' => $a->no_pos, 'tindakan2' => $a->_id )); } } }else{ $template = TemplateNotice::all(); foreach($template as $key => $a) { $n1 = ''; $aktif = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "Baru/"; }else{ $n1 = ""; } array_push($nested_data, array( 'index' => $n1.$a->jenis_amaran, 'no_rujukan' => $a->no_rujukan, 'tempoh' => $a->tempoh_hantar, 'status' => $a->status, 'tindakan' => $a->_id )); } } return \DataTables::of($nested_data)->make(true); } public function confirmTemplate(Request $request){ $template = TemplateNotice::where('_id',$request->id)->first(); if(!empty($template)){ $template->status = $request->status; $template->save(); return response()->json(['status' => 'true', 'desc' => 'Status templat notis amaran ini telah "'.$request->status.'"']); }else{ return response()->json(['status' => 'false', 'desc' => 'Rekod notis amaran tidak ditemui']); } } public function deleteTemplate(Request $request){ $template = TemplateNotice::with('Attachment')->where('_id',$request->id)->first(); if(!empty($template)){ if(!empty($template->Attachment)){ $template->attachment()->delete(); } $template->delete(); return response()->json(['status' => 'true', 'desc' => 'Buang rekod template notis amaran ( '.$template->no_rujukan.' )']); }else{ return response()->json(['status' => 'false', 'desc' => 'Buang rekod template notis amaran']); } } public function sendNotice(Request $request){ $template = TemplateNotice::with('Attachment')->where('_id',$request->id)->first(); if(!empty($template)){ return response()->json(['status' => 'true', 'desc' => 'Percubaan Hantar email ( '.$template->no_rujukan.' )']); }else{ return response()->json(['status' => 'false', 'desc' => 'Buang rekod template notis amaran ( '.$template->no_rujukan.' )']); } } /** * Create API list controller. * * @return json */ public function apiKeyList(){ $nested_data = array(); $api = ApiKey::orderBy('updated_at', 'desc')->get(); $curr = Carbon::now()->getTimestamp(); $i = 1; foreach($api as $a) { $n1 = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "New/"; }else{ $n1 = ""; } array_push($nested_data, array( 'index' => $n1.$a->name, 'key_prefix' => $a->key_prefix, 'scopes' => count($a->scopes). ' scopes enabled', 'action' => $a->_id, )); $i++; } return \DataTables::of($nested_data)->make(true); } public function deleteApiKey(Request $request){ $apiKey = ApiKey::where('_id', $request->id)->first(); if(!empty($apiKey)){ $apiKey->delete(); return response()->json(['status' => 'true', 'desc' => 'Successfully delete Api Key']); }else{ return response()->json(['status' => 'false', 'desc' => 'Record Api Key not found!']); } } public function apiKeyIntegrationList(){ $nested_data = array(); $curr = Carbon::now()->getTimestamp(); $i = 1; $api = ApiIntegration::with('ApiKey')->orderBy('created_at', 'desc')->get(); foreach($api as $a) { $n1 = ''; $reg_time = $a->created_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "New/"; }else{ $n1 = ""; } if(!empty($a->ApiKey)){ array_push($nested_data, array( 'index' => $n1.$a->updated_at->toDateTimeString(), 'client' => $a->client, 'api' => $a->ApiKey->scopes, 'key' => $a->key, 'status' => $a->status )); $i++; } } return \DataTables::of($nested_data)->make(true); } }