159 lines
4.7 KiB
PHP
159 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\DashboardAdaptationService;
|
|
use App\Services\DashboardMitigationService;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\LembarPengesahan;
|
|
|
|
class LembarPengesahanController extends Controller
|
|
{
|
|
protected $title = 'Lembar Pengesahan';
|
|
protected $template = 'modules.pengesahan';
|
|
protected $route = 'modules.pengesahan';
|
|
|
|
public function __construct(DashboardAdaptationService $adaptationService,DashboardMitigationService $mitigationService)
|
|
{
|
|
$this->adaptationService = $adaptationService;
|
|
$this->mitigationService = $mitigationService;
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$data['route'] = $this->route;
|
|
$data['title'] = $this->title;
|
|
|
|
return view($this->template.'.index',$data);
|
|
}
|
|
|
|
public function grid()
|
|
{
|
|
$data = LembarPengesahaan::where('tahun',date('Y'))->get();
|
|
$_data = [];
|
|
|
|
foreach ($data as $key => $row) {
|
|
|
|
$btn = '<a href="' . url('master/agency/update/').'/'.encode_id($row->id). '" class="btn btn-sm w-100 mb-1 btn-primary">Edit</a>';
|
|
$btn .= ' <form action="' . route($this->route.'.destroy', $row->id) . '" method="POST" style="display: inline;" class="delete-form">';
|
|
$btn .= csrf_field();
|
|
$btn .= method_field('DELETE');
|
|
$btn .= '<button type="button" class="btn btn-sm btn-danger delete-button remove_data">Hapus</button>';
|
|
$btn .= '</form>';
|
|
|
|
if ($row->row_status == 1) {
|
|
$status = '<span class="badge bg-success">Aktif</span>';
|
|
} else {
|
|
$status = '<span class="badge bg-danger">Tidak Aktif</span>';
|
|
}
|
|
|
|
$_data[] = [
|
|
'no' => $key+1,
|
|
'name' => $row->name,
|
|
'scope' => $row->scope,
|
|
'status' => $status,
|
|
'action' => @$btn,
|
|
];
|
|
|
|
}
|
|
|
|
return response()->json($_data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
$year = (int) request()->input('adaptationYear', date('Y'));
|
|
$adaptasi = $this->adaptationService->getDashboardData($year);
|
|
$mitigasi = $this->mitigationService->getDashboardData($year);
|
|
|
|
|
|
$data['route'] = $this->route;
|
|
$data['title'] = $this->title;
|
|
$data['kegiatanAdaptasi'] = $adaptasi['tableData'];
|
|
$data['kegiatanMitigasi'] = $mitigasi['tableData'];
|
|
|
|
return view($this->template.'.form',$data);
|
|
}
|
|
|
|
public function update($id = null)
|
|
{
|
|
$keyId = decode_id($id);
|
|
$data['title'] = $this->title;
|
|
$data['route'] = $this->route;
|
|
$data['keyId'] = $id;
|
|
$data['item'] = LembarPengesahaan::where('id',$keyId)->first();
|
|
|
|
return view($this->template.'.form',$data);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'agency_id' => '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->save();
|
|
}else{
|
|
$ag = new LembarPengesahan;
|
|
$ag->agency_id = $request->agency_id;
|
|
$ag->type = $request->type;
|
|
$ag->file = $request->file;
|
|
$ag->status = 1;
|
|
$ag->save();
|
|
}
|
|
|
|
return redirect()->route($this->route.'.index')->with('success', 'Lembar Pengesahan berhasil ditambahkan.');
|
|
} catch (\Exception $e) {
|
|
return back()->withErrors(['error' => 'Lembar Pengesahan gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage()]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(string $id)
|
|
{
|
|
$data['ar'] = LembarPengesahaan::find($id);
|
|
$data['route'] = $this->route;
|
|
$data['title'] = $this->title;
|
|
return view($this->template.'.form', $data);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $id)
|
|
{
|
|
//
|
|
}
|
|
}
|