update
parent
12b9db685b
commit
a3326d683d
|
|
@ -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 = '<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 = '<a href="' . url('pengesahan/update/').'/'.encode_id($row->LembarPengesahanId). '" class="btn btn-sm w-100 mb-1 btn-primary">Edit</a>';
|
||||
$btn .= ' <form action="' . route($this->route.'.destroy', $row->LembarPengesahanId) . '" 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>';
|
||||
|
||||
$download = '<a class="btn btn-primary btn-sm w-100" href="'.asset('uploads/'.$row->file).'">Download File</a>';
|
||||
|
||||
$datanya = '';
|
||||
if($row->type == 'inventory'){
|
||||
$sektor = json_decode($row->sektor);
|
||||
foreach($sektor as $datasek){
|
||||
$datanya .= '<span class="badge bg-danger w-100">'.$datasek.'</span><br>';
|
||||
}
|
||||
}elseif($row->type == 'adaptasi'){
|
||||
|
||||
$datanya .= '';
|
||||
}elseif($row->type == 'mitigasi'){
|
||||
$datanya .= '';
|
||||
}
|
||||
|
||||
if ($row->row_status == 1) {
|
||||
$status = '<span class="badge bg-success">Aktif</span>';
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -20,7 +20,7 @@
|
|||
<div class="form-group">
|
||||
<label class="col-xl-12 form-label">Jenis Pengesahan</label>
|
||||
<div class="col-12 ">
|
||||
<select name="type" class="form-control select2 type" id="" required>
|
||||
<select name="type" class="form-control select2 type" required>
|
||||
<option value="">-- PILIH JENIS PENGESAHAN --</option>
|
||||
<option {{@$item->type == 'adaptasi' ? 'selected' : ''}} value="adaptasi">Adaptasi</option>
|
||||
<option {{@$item->type == 'mitigasi' ? 'selected' : ''}} value="mitigasi">Mitigasi</option>
|
||||
|
|
@ -33,57 +33,71 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 mb-3 d-none inventory">
|
||||
<div class="col-12 mb-3 {{ @$item->type == 'inventory' ? '' : 'd-none' }} inventory">
|
||||
<div class="form-group">
|
||||
<label class="col-xl-12 form-label">Sektor</label>
|
||||
<div class="col-12 ">
|
||||
<select name="sektor[]" class="form-control select2" id="" required multiple>
|
||||
<optgroup label="Energi">
|
||||
<option value="Pembangkit Listrik">Pembangkit Listrik</option>
|
||||
<option value="Industri Manufaktur">Industri Manufaktur</option>
|
||||
<option value="Transportasi">Transportasi</option>
|
||||
<option value="Komersial">Komersial</option>
|
||||
<option value="Rumah Tangga">Rumah Tangga</option>
|
||||
<option value="Energi Lainnya">Energi Lainnya</option>
|
||||
<option value="Penggunaan Listrik PLN">Penggunaan Listrik PLN</option>
|
||||
<option value="Transmisi & Distribusi">Transmisi & Distribusi</option>
|
||||
<option value="Penyulingan">Penyulingan</option>
|
||||
<option value="Penggunaan Listrik">Penggunaan Listrik</option>
|
||||
<option value="Bahan Bakar Listrik">Bahan Bakar Listrik</option>
|
||||
<option value="Emisi Fugitive Batu Bara">Emisi Fugitive Batu Bara</option>
|
||||
<option value="Emisi Fugitive Migas">Emisi Fugitive Migas</option>
|
||||
</optgroup>
|
||||
<optgroup label="IPPU">
|
||||
<option value="Produksi">Produksi</option>
|
||||
<option value="Pelumas & Parafin">Pelumas & Parafin</option>
|
||||
<option value="Karbonat Kaca">Karbonat Kaca</option>
|
||||
<option value="Karbonat Keramik">Karbonat Keramik</option>
|
||||
<option value="Karbonat Lainnya">Karbonat Lainnya</option>
|
||||
<option value="Karbonat Pulp Paper">Karbonat Pulp Paper</option>
|
||||
<option value="Karbonat Makanan & Minuman">Karbonat Makanan & Minuman</option>
|
||||
<option value="Penggunaan AC">Penggunaan AC</option>
|
||||
</optgroup>
|
||||
<optgroup label="Pertanian & Lahan">
|
||||
<option value="Pengelolaan Kotoran Ternak">Pengelolaan Kotoran Ternak</option>
|
||||
<option value="Populasi Ternak">Populasi Ternak</option>
|
||||
<option value="Sawah">Sawah</option>
|
||||
<option value="Tanaman Pangan">Tanaman Pangan</option>
|
||||
<option value="Konsumsi Pupuk">Konsumsi Pupuk</option>
|
||||
<option value="Hortikultura">Hortikultura</option>
|
||||
<option value="Pengairan Sawah">Pengairan Sawah</option>
|
||||
<option value="Sistem Air Sebelum Penananman Padi Sawah">Sistem Air Sebelum Penananman Padi Sawah</option>
|
||||
<option value="Matriks Transisi Pertumbuhan Tutupan Lahan">Matriks Transisi Pertumbuhan Tutupan Lahan</option>
|
||||
<option value="Kehilangan Kayu">Kehilangan Kayu</option>
|
||||
<option value="Perubahan Lahan Pemukiman">Perubahan Lahan Pemukiman</option>
|
||||
</optgroup>
|
||||
<optgroup label="Limbah">
|
||||
<option value="Kependudukan">Kependudukan</option>
|
||||
<option value="Timbulan Sampah">Timbulan Sampah</option>
|
||||
<option value="Distribusi Sampah Domestik">Distribusi Sampah Domestik</option>
|
||||
<option value="Sarana Air Limbah Domestik">Sarana Air Limbah Domestik</option>
|
||||
<option value="Limbah Cair Industri">Limbah Cair Industri</option>
|
||||
</optgroup>
|
||||
|
||||
@php
|
||||
$selectedSektor = json_decode($item->sektor, true) ?? [];
|
||||
|
||||
$options = [
|
||||
'Energi' => [
|
||||
'Pembangkit Listrik',
|
||||
'Industri Manufaktur',
|
||||
'Transportasi',
|
||||
'Komersial',
|
||||
'Rumah Tangga',
|
||||
'Energi Lainnya',
|
||||
'Penggunaan Listrik PLN',
|
||||
'Transmisi & Distribusi',
|
||||
'Penyulingan',
|
||||
'Penggunaan Listrik',
|
||||
'Bahan Bakar Listrik',
|
||||
'Emisi Fugitive Batu Bara',
|
||||
'Emisi Fugitive Migas',
|
||||
],
|
||||
'IPPU' => [
|
||||
'Produksi',
|
||||
'Pelumas & Parafin',
|
||||
'Karbonat Kaca',
|
||||
'Karbonat Keramik',
|
||||
'Karbonat Lainnya',
|
||||
'Karbonat Pulp Paper',
|
||||
'Karbonat Makanan & Minuman',
|
||||
'Penggunaan AC',
|
||||
],
|
||||
'Pertanian & Lahan' => [
|
||||
'Pengelolaan Kotoran Ternak',
|
||||
'Populasi Ternak',
|
||||
'Sawah',
|
||||
'Tanaman Pangan',
|
||||
'Konsumsi Pupuk',
|
||||
'Hortikultura',
|
||||
'Pengairan Sawah',
|
||||
'Sistem Air Sebelum Penananman Padi Sawah',
|
||||
'Matriks Transisi Pertumbuhan Tutupan Lahan',
|
||||
'Kehilangan Kayu',
|
||||
'Perubahan Lahan Pemukiman',
|
||||
],
|
||||
'Limbah' => [
|
||||
'Kependudukan',
|
||||
'Timbulan Sampah',
|
||||
'Distribusi Sampah Domestik',
|
||||
'Sarana Air Limbah Domestik',
|
||||
'Limbah Cair Industri',
|
||||
]
|
||||
];
|
||||
@endphp
|
||||
<select name="sektor[]" class="form-control select2" multiple>
|
||||
@foreach($options as $group => $items)
|
||||
<optgroup label="{{ $group }}">
|
||||
@foreach($items as $opt)
|
||||
<option value="{{ $opt }}" {{ in_array($opt, $selectedSektor) ? 'selected' : '' }}>
|
||||
{{ $opt }}
|
||||
</option>
|
||||
@endforeach
|
||||
</optgroup>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('type')
|
||||
<span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
|
||||
|
|
@ -94,11 +108,12 @@
|
|||
|
||||
|
||||
|
||||
<div class="col-12 mb-3 d-none adaptasi">
|
||||
<div class="col-12 mb-3 {{ @$item->type == 'adaptasi' ? '' : 'd-none' }} adaptasi">
|
||||
<div class="form-group">
|
||||
<label class="col-xl-12 form-label">Kegiatan Adaptasi</label>
|
||||
<div class="col-12 ">
|
||||
<select name="kegiatan_adaptasi[]" class="form-control select2" multiple id="" required>
|
||||
<select name="kegiatan_adaptasi[]" class="form-control select2" multiple>
|
||||
<option value="">-- PILIH KEGIATAN ADAPTASI --</option>
|
||||
@foreach($kegiatanAdaptasi as $a)
|
||||
<option value="{{ $a->id }}">
|
||||
{{ $a->nama_kegiatan }} >>
|
||||
|
|
@ -114,11 +129,12 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 mb-3 d-none mitigasi">
|
||||
<div class="col-12 mb-3 {{ @$item->type == 'mitigasi' ? '' : 'd-none' }} mitigasi">
|
||||
<div class="form-group">
|
||||
<label class="col-xl-12 form-label">Kegiatan Mitigasi</label>
|
||||
<div class="col-12 ">
|
||||
<select name="kegiatan_mitigasi[]" class="form-control select2" multiple id="" required>
|
||||
<select name="kegiatan_mitigasi[]" class="form-control select2" multiple>
|
||||
<option value="">-- PILIH KEGIATAN MITIGASI --</option>
|
||||
@foreach($kegiatanMitigasi as $m)
|
||||
<option value="{{ $m->id }}">
|
||||
{{ Str::limit($m->nama_kegiatan, 60) }} >>
|
||||
|
|
@ -138,7 +154,7 @@
|
|||
<div class="form-group">
|
||||
<label class="col-xl-12 form-label">Keterangan (Opsional)</label>
|
||||
<div class="col-12 ">
|
||||
<textarea name="keterangan" class="form-control" id="" cols="10" rows="5">{{@$item->keterangan}}</textarea>
|
||||
<textarea name="keterangan" class="form-control" cols="10" rows="5">{{@$item->keterangan}}</textarea>
|
||||
@error('keterangan')
|
||||
<span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
|
||||
@enderror
|
||||
|
|
@ -149,7 +165,7 @@
|
|||
<div class="form-group">
|
||||
<label class="col-xl-12 form-label">File Dokumen</label>
|
||||
<div class="col-12 ">
|
||||
<input type="file" name="file" accept=".pdf" class="form-control" id="">
|
||||
<input type="file" name="file" accept=".pdf" class="form-control">
|
||||
@error('file')
|
||||
<span class="invalid-feedback" style="display: block!important;"><strong>{{$message}}</strong></span>
|
||||
@enderror
|
||||
|
|
@ -163,7 +179,7 @@
|
|||
<div class="row">
|
||||
<div class="col-md-12 text-right">
|
||||
<a href="{{route($route.'.index')}}" class="btn btn-danger"><i class="mdi mdi-cancel"></i> Batal</a>
|
||||
<button type="submit" class="btn btn-success"><i class="mdi mdi-content-save-outline"></i> Simpan</button>
|
||||
<button class="btn btn-success"><i class="mdi mdi-content-save-outline"></i> Simpan</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -33,8 +33,9 @@
|
|||
<th data-width="15%" class="text-center" data-field="action">#</th>
|
||||
<th data-field="agency">Instansi</th>
|
||||
<th data-field="type">Jenis Pengesahan</th>
|
||||
<th data-field="data">Data</th>
|
||||
<th data-field="file">File</th>
|
||||
<th data-field="status">Status</th>
|
||||
{{-- <th data-field="status">Status</th> --}}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
|
|
|
|||
Loading…
Reference in New Issue