diff --git a/app/Http/Controllers/LembarPengesahanController.php b/app/Http/Controllers/LembarPengesahanController.php index 5b6b5f6..acd806b 100644 --- a/app/Http/Controllers/LembarPengesahanController.php +++ b/app/Http/Controllers/LembarPengesahanController.php @@ -5,6 +5,8 @@ namespace App\Http\Controllers; use App\Services\DashboardAdaptationService; use App\Services\DashboardMitigationService; use Illuminate\Http\Request; +use Illuminate\Support\Facades\File; +use Carbon\Carbon; use App\Models\LembarPengesahan; class LembarPengesahanController extends Controller @@ -32,17 +34,36 @@ class LembarPengesahanController extends Controller public function grid() { - $data = LembarPengesahaan::where('tahun',date('Y'))->get(); + if(auth()->user()->ms_group_id == 1){ + $data = LembarPengesahan::with(['agency'])->where('tahun',date('Y'))->get(); + }else{ + $data = LembarPengesahan::with(['agency'])->where('tahun',date('Y'))->where('agency_id',auth()->user()->ms_agency_id)->get(); + } $_data = []; foreach ($data as $key => $row) { - $btn = 'Edit'; - $btn .= '
'; + $btn = 'Edit'; + $btn .= ' '; $btn .= csrf_field(); $btn .= method_field('DELETE'); $btn .= ''; $btn .= '
'; + + $download = 'Download File'; + + $datanya = ''; + if($row->type == 'inventory'){ + $sektor = json_decode($row->sektor); + foreach($sektor as $datasek){ + $datanya .= ''.$datasek.'
'; + } + }elseif($row->type == 'adaptasi'){ + + $datanya .= ''; + }elseif($row->type == 'mitigasi'){ + $datanya .= ''; + } if ($row->row_status == 1) { $status = 'Aktif'; @@ -53,7 +74,10 @@ class LembarPengesahanController extends Controller $_data[] = [ 'no' => $key+1, 'name' => $row->name, - 'scope' => $row->scope, + 'type' => \Str::title($row->type), + 'agency' => $row->agency->name, + 'file' => $download, + 'data' => @$datanya, 'status' => $status, 'action' => @$btn, ]; @@ -83,11 +107,17 @@ class LembarPengesahanController extends Controller public function update($id = null) { + $year = (int) request()->input('adaptationYear', date('Y')); + $adaptasi = $this->adaptationService->getDashboardData($year); + $mitigasi = $this->mitigationService->getDashboardData($year); + $keyId = decode_id($id); $data['title'] = $this->title; $data['route'] = $this->route; $data['keyId'] = $id; - $data['item'] = LembarPengesahaan::where('id',$keyId)->first(); + $data['kegiatanAdaptasi'] = $adaptasi['tableData']; + $data['kegiatanMitigasi'] = $mitigasi['tableData']; + $data['item'] = LembarPengesahan::find($keyId); return view($this->template.'.form',$data); } @@ -98,23 +128,87 @@ class LembarPengesahanController extends Controller public function store(Request $request) { $request->validate([ - 'agency_id' => 'required', - 'file' => 'required', + // 'file' => 'required', 'type' => 'required', ]); try { if(@$request->secure_id){ - $ag = LembarPengesahaan::find(decode_id(@$request->secure_id)); - $ag->agency_id = $request->agency_id; - $ag->type = $request->type; - $ag->file = $request->file; + $ag = LembarPengesahan::find(decode_id(@$request->secure_id)); + $ag->keterangan = $request->keterangan; + + if($request->type == 'inventory'){ + $ag->sektor = json_encode($request->sektor); + }elseif($request->type == 'adaptasi'){ + $ag->form_id = json_encode($request->kegiatan_adaptasi); + }elseif($request->type == 'mitigasi'){ + $ag->form_id = json_encode($request->kegiatan_mitigasi); + } + + if (@$request->hasFile('file')) { + $file = $request->file('file'); + $destinationPath = public_path('uploads/pengesahan'); + $current = Carbon::now()->format('Y/m/d'); + $path = $destinationPath . '/' . $current; + $fileExtension = $file->getClientOriginalExtension(); + $fileSize = $file->getSize(); + if($fileExtension != 'pdf'){ + return redirect()->back()->with([ + 'message' => 'Maaf File Harus Berupa PDF!', + 'type' => "error" + ]); + } + $newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension; + + if (!File::exists($path)) { + File::isDirectory($path) or File::makeDirectory($path, 0777, true, true); + } + + $filePathTim = 'pengesahan/' . $current . '/' . $newFilename; + $uploaded = $file->move($path, $newFilename); + $ag->file = $filePathTim; + } $ag->save(); }else{ $ag = new LembarPengesahan; - $ag->agency_id = $request->agency_id; + $ag->user_id = auth()->user()->id; + $ag->agency_id = auth()->user()->ms_agency_id; + $ag->tahun = date('Y'); $ag->type = $request->type; - $ag->file = $request->file; + $ag->keterangan = $request->keterangan; + + if($request->type == 'inventory'){ + $ag->sektor = json_encode($request->sektor); + }elseif($request->type == 'adaptasi'){ + $ag->form_id = json_encode($request->kegiatan_adaptasi); + }elseif($request->type == 'mitigasi'){ + $ag->form_id = json_encode($request->kegiatan_mitigasi); + } + + if (@$request->hasFile('file')) { + $file = $request->file('file'); + $destinationPath = public_path('uploads/pengesahan'); + $current = Carbon::now()->format('Y/m/d'); + $path = $destinationPath . '/' . $current; + $fileExtension = $file->getClientOriginalExtension(); + $fileSize = $file->getSize(); + if($fileExtension != 'pdf'){ + return redirect()->back()->with([ + 'message' => 'Maaf File Harus Berupa PDF!', + 'type' => "error" + ]); + } + $newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension; + + if (!File::exists($path)) { + File::isDirectory($path) or File::makeDirectory($path, 0777, true, true); + } + + $filePathTim = 'pengesahan/' . $current . '/' . $newFilename; + $uploaded = $file->move($path, $newFilename); + } + + $ag->file = $filePathTim; $ag->status = 1; $ag->save(); } @@ -138,7 +232,7 @@ class LembarPengesahanController extends Controller */ public function edit(string $id) { - $data['ar'] = LembarPengesahaan::find($id); + $data['ar'] = LembarPengesahan::find($id); $data['route'] = $this->route; $data['title'] = $this->title; return view($this->template.'.form', $data); diff --git a/app/Models/LembarPengesahan.php b/app/Models/LembarPengesahan.php index 2ab593c..c2212e0 100644 --- a/app/Models/LembarPengesahan.php +++ b/app/Models/LembarPengesahan.php @@ -11,4 +11,8 @@ class LembarPengesahan extends Model protected $table = 'lembar_pengesahan'; protected $primaryKey = 'LembarPengesahanId'; protected $guarded = []; + + function agency(){ + return $this->belongsTo(\App\Models\Agency::class,'agency_id'); + } } diff --git a/public/uploads/pengesahan/2026/04/28/_file_69f071dcc043c.pdf b/public/uploads/pengesahan/2026/04/28/_file_69f071dcc043c.pdf new file mode 100644 index 0000000..f2fc123 Binary files /dev/null and b/public/uploads/pengesahan/2026/04/28/_file_69f071dcc043c.pdf differ diff --git a/resources/views/modules/pengesahan/form.blade.php b/resources/views/modules/pengesahan/form.blade.php index 267ce95..6904f34 100644 --- a/resources/views/modules/pengesahan/form.blade.php +++ b/resources/views/modules/pengesahan/form.blade.php @@ -20,7 +20,7 @@
- @@ -33,57 +33,71 @@
-
+
- + @foreach($options as $group => $items) + + @foreach($items as $opt) + + @endforeach + + @endforeach @error('type') {{$message}} @@ -94,11 +108,12 @@ -
+
- + @foreach($kegiatanAdaptasi as $a)
-
+
- + @foreach($kegiatanMitigasi as $m)