123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- <?php
-
- namespace App\Http\Controllers\api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Api\BaseController;
-
- use Config;
- use File;
- use Carbon\Carbon;
-
- use App\Model\Staff;
- use App\Model\StaffDetail;
- use App\Model\Module\Roles;
- use App\Model\Module\Department;
- use App\Model\Module\Faulty;
- use App\Model\Module\Memo;
- use App\Model\Module\Compound;
- use App\Model\Module\ConfidentialFile;
- use App\Model\Module\TemplateNotice;
- use App\Model\Module\Attachment;
- use App\Model\Module\History;
- use App\Model\Module\SubHistory;
- use App\Model\Module\LetterNotice;
- use App\Model\Module\ApiKey;
- use App\Model\Module\ApiIntegration;
-
- use App\Jobs\UpdateCompoundPrice;
- use App\Jobs\SendNoticeLetter;
-
- class SettingController extends BaseController
- {
-
- /**
- * Create a memo list controller.
- *
- * @return json
- */
-
- public function memoList(){
-
- $nested_data = array();
- $memo = Memo::with('Attachment')->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." <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>.",
- ];
-
- $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." <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>.",
- ];
-
- $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." <a href='".url('/main/staff')."/".$staffD->_id."/profile'>".$staffD->StaffDetail->full_name."</a> 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." <a href='".url('/main/staff')."/".$staffD->_id."/profile'>".$staffD->StaffDetail->full_name."</a>.";
- }
-
- $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);
-
- }
- }
|