128 lines
3.1 KiB
PHP
128 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\SampahTerkelola;
|
|
|
|
class SampahController extends Controller
|
|
{
|
|
protected $template = 'modules.sampah';
|
|
protected $route = 'modules.sampah';
|
|
protected $title = 'Sampah Terkelola';
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$data['title'] = $this->title;
|
|
$data['route'] = $this->route;
|
|
return view($this->template.'.index', $data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
public function grid(Request $request)
|
|
{
|
|
|
|
$data = SampahTerkelola::where('ms_sekolah_id',session('sekolah_id'))
|
|
->orderBy('tahun','DESC')
|
|
->orderBy('bulan','ASC')
|
|
->get();
|
|
$_data = [];
|
|
|
|
|
|
foreach ($data as $key => $row) {
|
|
|
|
$_data[] = [
|
|
'no' => $key+1,
|
|
'id' => encode_id($row->SampahTekelolaId),
|
|
'tahun' => $row->tahun,
|
|
'bulan' => monthtString($row->bulan),
|
|
'organik' => $row->organik,
|
|
'sampah_anorganik' => $row->sampah_anorganik,
|
|
'b3' => $row->b3,
|
|
'minyak_jelantah' => $row->minyak_jelantah,
|
|
];
|
|
|
|
}
|
|
|
|
// return response()->json($_data); // Return the data as a JSON response
|
|
return response()->json($_data);
|
|
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
try {
|
|
$data = SampahTerkelola::updateOrCreate([
|
|
'tahun' => date('Y'),
|
|
'bulan' => $request->bulan,
|
|
'ms_sekolah_id' => session('sekolah_id'),
|
|
],[
|
|
'tahun' => date('Y'),
|
|
'ms_sekolah_id' => session('sekolah_id'),
|
|
'bulan' => $request->bulan,
|
|
'organik' => $request->organik,
|
|
'sampah_anorganik' => $request->anorganik,
|
|
'b3' => $request->b3,
|
|
'minyak_jelantah' => $request->minyak_jelantah,
|
|
]);
|
|
|
|
return redirect()->back()->with([
|
|
'message' => 'Berhasil update data',
|
|
'type' => 'success',
|
|
]);
|
|
} catch (\Throwable $th) {
|
|
//throw $th;
|
|
|
|
dd($th);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $id)
|
|
{
|
|
//
|
|
}
|
|
}
|