baru lagi
|
|
@ -17,6 +17,7 @@ public function index()
|
|||
|
||||
$sampah = Sampah::with('user')
|
||||
->orderBy('tahun', 'desc')
|
||||
->orderBy('bulan', 'desc')
|
||||
->get();
|
||||
|
||||
return view('admin.sampah.index', compact('title', 'sampah'));
|
||||
|
|
@ -30,76 +31,38 @@ public function create()
|
|||
return view('admin.sampah.create', compact('title', 'users'));
|
||||
}
|
||||
|
||||
/* ======================================================
|
||||
STORE (TAMBAH DATA)
|
||||
====================================================== */
|
||||
public function store(Request $request)
|
||||
{
|
||||
// ===============================
|
||||
// KONVERSI FORMAT INDONESIA
|
||||
// ===============================
|
||||
$request->merge([
|
||||
'total_sampah' => $this->convertToDecimal($request->total_sampah),
|
||||
'total_kelola' => $this->convertToDecimal($request->total_kelola),
|
||||
'total_daur_ulang' => $this->convertToDecimal($request->total_daur_ulang),
|
||||
]);
|
||||
|
||||
// ===============================
|
||||
// VALIDASI
|
||||
// ===============================
|
||||
$validator = Validator::make(
|
||||
$request->all(),
|
||||
[
|
||||
$validator = Validator::make($request->all(), [
|
||||
'tahun' => 'required|digits:4',
|
||||
'bulan' => 'required|integer|min:1|max:12',
|
||||
'total_sampah' => 'required|numeric|min:0',
|
||||
'total_kelola' => 'required|numeric|min:0',
|
||||
'total_daur_ulang' => 'required|numeric|min:0',
|
||||
],
|
||||
[
|
||||
'tahun.required' => 'Tahun wajib diisi.',
|
||||
'tahun.digits' => 'Tahun harus 4 digit (contoh: 2024).',
|
||||
|
||||
'total_sampah.required' => 'Total sampah wajib diisi.',
|
||||
'total_sampah.numeric' => 'Total sampah harus berupa angka.',
|
||||
'total_sampah.min' => 'Total sampah tidak boleh negatif.',
|
||||
|
||||
'total_kelola.required' => 'Total kelola wajib diisi.',
|
||||
'total_kelola.numeric' => 'Total kelola harus berupa angka.',
|
||||
'total_kelola.min' => 'Total kelola tidak boleh negatif.',
|
||||
|
||||
'total_daur_ulang.required' => 'Total daur ulang wajib diisi.',
|
||||
'total_daur_ulang.numeric' => 'Total daur ulang harus berupa angka.',
|
||||
'total_daur_ulang.min' => 'Total daur ulang tidak boleh negatif.',
|
||||
]
|
||||
);
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// VALIDASI LOGIKA
|
||||
// ===============================
|
||||
if (($request->total_kelola + $request->total_daur_ulang) > $request->total_sampah) {
|
||||
return back()
|
||||
->withErrors([
|
||||
'total_kelola' => 'Jumlah kelola + daur ulang tidak boleh melebihi total sampah.',
|
||||
])
|
||||
->withInput();
|
||||
return back()->withErrors([
|
||||
'total_kelola' => 'Jumlah kelola + daur ulang tidak boleh melebihi total sampah.'
|
||||
])->withInput();
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// HITUNG SISA
|
||||
// ===============================
|
||||
$sisa_sampah = $request->total_sampah
|
||||
- ($request->total_kelola + $request->total_daur_ulang);
|
||||
$sisa_sampah = $request->total_sampah - ($request->total_kelola + $request->total_daur_ulang);
|
||||
|
||||
// ===============================
|
||||
// SIMPAN DATA
|
||||
// ===============================
|
||||
Sampah::create([
|
||||
'user_id' => Auth::id(),
|
||||
'tahun' => $request->tahun,
|
||||
'bulan' => $request->bulan,
|
||||
'total_sampah' => $request->total_sampah,
|
||||
'total_kelola' => $request->total_kelola,
|
||||
'total_daur_ulang' => $request->total_daur_ulang,
|
||||
|
|
@ -110,91 +73,48 @@ public function store(Request $request)
|
|||
->with('success', 'Data sampah berhasil ditambahkan.');
|
||||
}
|
||||
|
||||
/* ======================================================
|
||||
EDIT
|
||||
====================================================== */
|
||||
public function edit($id)
|
||||
{
|
||||
$title = 'Edit Data Sampah';
|
||||
$sampah = Sampah::findOrFail($id);
|
||||
$users = User::all();
|
||||
|
||||
return view('admin.sampah.edit', compact('title', 'sampah', 'users'));
|
||||
return view('admin.sampah.edit', compact('title', 'sampah'));
|
||||
}
|
||||
|
||||
/* ======================================================
|
||||
UPDATE
|
||||
====================================================== */
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$sampah = Sampah::findOrFail($id);
|
||||
|
||||
// ===============================
|
||||
// KONVERSI FORMAT INDONESIA
|
||||
// ===============================
|
||||
$request->merge([
|
||||
'total_sampah' => $this->convertToDecimal($request->total_sampah),
|
||||
'total_kelola' => $this->convertToDecimal($request->total_kelola),
|
||||
'total_daur_ulang' => $this->convertToDecimal($request->total_daur_ulang),
|
||||
]);
|
||||
|
||||
// ===============================
|
||||
// VALIDASI
|
||||
// ===============================
|
||||
$validator = Validator::make(
|
||||
$request->all(),
|
||||
[
|
||||
'user_id' => 'required|exists:users,id',
|
||||
$validator = Validator::make($request->all(), [
|
||||
'tahun' => 'required|digits:4',
|
||||
'bulan' => 'required|integer|min:1|max:12',
|
||||
'total_sampah' => 'required|numeric|min:0',
|
||||
'total_kelola' => 'required|numeric|min:0',
|
||||
'total_daur_ulang' => 'required|numeric|min:0',
|
||||
],
|
||||
[
|
||||
'user_id.required' => 'Pengguna wajib dipilih.',
|
||||
'user_id.exists' => 'Pengguna tidak valid.',
|
||||
|
||||
'tahun.required' => 'Tahun wajib diisi.',
|
||||
'tahun.digits' => 'Tahun harus 4 digit.',
|
||||
|
||||
'total_sampah.required' => 'Total sampah wajib diisi.',
|
||||
'total_sampah.numeric' => 'Total sampah harus berupa angka.',
|
||||
|
||||
'total_kelola.required' => 'Total kelola wajib diisi.',
|
||||
'total_kelola.numeric' => 'Total kelola harus berupa angka.',
|
||||
|
||||
'total_daur_ulang.required' => 'Total daur ulang wajib diisi.',
|
||||
'total_daur_ulang.numeric' => 'Total daur ulang harus berupa angka.',
|
||||
]
|
||||
);
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// VALIDASI LOGIKA
|
||||
// ===============================
|
||||
if (($request->total_kelola + $request->total_daur_ulang) > $request->total_sampah) {
|
||||
return back()
|
||||
->withErrors([
|
||||
'total_kelola' => 'Jumlah kelola + daur ulang tidak boleh melebihi total sampah.',
|
||||
])
|
||||
->withInput();
|
||||
return back()->withErrors([
|
||||
'total_kelola' => 'Jumlah kelola + daur ulang tidak boleh melebihi total sampah.'
|
||||
])->withInput();
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// HITUNG SISA
|
||||
// ===============================
|
||||
$sisa_sampah = $request->total_sampah
|
||||
- ($request->total_kelola + $request->total_daur_ulang);
|
||||
$sisa_sampah = $request->total_sampah - ($request->total_kelola + $request->total_daur_ulang);
|
||||
|
||||
// ===============================
|
||||
// UPDATE DATA
|
||||
// ===============================
|
||||
$sampah->update([
|
||||
'user_id' => $request->user_id,
|
||||
'user_id' => Auth::id(),
|
||||
'tahun' => $request->tahun,
|
||||
'bulan' => $request->bulan,
|
||||
'total_sampah' => $request->total_sampah,
|
||||
'total_kelola' => $request->total_kelola,
|
||||
'total_daur_ulang' => $request->total_daur_ulang,
|
||||
|
|
@ -214,16 +134,12 @@ public function destroy($id)
|
|||
->with('success', 'Data sampah berhasil dihapus.');
|
||||
}
|
||||
|
||||
/* ======================================================
|
||||
HELPER KONVERSI FORMAT INDONESIA
|
||||
====================================================== */
|
||||
private function convertToDecimal($value)
|
||||
{
|
||||
if (!$value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// hapus titik ribuan lalu ubah koma jadi titik
|
||||
return str_replace(',', '.', str_replace('.', '', $value));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,42 @@
|
|||
class IndexController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
{
|
||||
$tahun = date('Y');
|
||||
|
||||
// Ambil data sampah per bulan
|
||||
$dataSampah = Sampah::where('tahun', $tahun)
|
||||
->orderBy('bulan')
|
||||
->get();
|
||||
|
||||
$bulan = [];
|
||||
$timbulan = [];
|
||||
$kelola = [];
|
||||
$daur = [];
|
||||
$sisa = [];
|
||||
|
||||
foreach ($dataSampah as $d) {
|
||||
$bulan[] = \Carbon\Carbon::create()->month($d->bulan)->translatedFormat('M');
|
||||
$timbulan[] = $d->total_sampah;
|
||||
$kelola[] = $d->total_kelola;
|
||||
$daur[] = $d->total_daur_ulang;
|
||||
$sisa[] = $d->sisa_sampah;
|
||||
}
|
||||
|
||||
// Rekap total satu tahun
|
||||
$rekap = [
|
||||
'timbulan' => array_sum($timbulan),
|
||||
'kelola' => array_sum($kelola),
|
||||
'daur' => array_sum($daur),
|
||||
'sisa' => array_sum($sisa),
|
||||
];
|
||||
|
||||
// Data sampah terbaru untuk card
|
||||
$sampah = Sampah::orderBy('tahun', 'desc')->first();
|
||||
|
||||
// Data TPS
|
||||
$kategoriTps = KategoriTps::orderBy('id_kategori_tps')->get();
|
||||
|
||||
$tps = LokasiTps::all(); // disamakan dengan yang dipakai di view
|
||||
$tps = LokasiTps::all();
|
||||
|
||||
$jumlahTps = LokasiTps::where('kategori_tps_id', 1)->count();
|
||||
$jumlahTps3r = LokasiTps::where('kategori_tps_id', 2)->count();
|
||||
|
|
@ -27,7 +57,14 @@ public function index()
|
|||
'tps',
|
||||
'jumlahTps',
|
||||
'jumlahTps3r',
|
||||
'jumlahTpa'
|
||||
'jumlahTpa',
|
||||
'bulan',
|
||||
'timbulan',
|
||||
'kelola',
|
||||
'daur',
|
||||
'sisa',
|
||||
'rekap',
|
||||
'tahun'
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,16 +12,13 @@ class Sampah extends Model
|
|||
protected $fillable = [
|
||||
'user_id',
|
||||
'tahun',
|
||||
'bulan',
|
||||
'total_sampah',
|
||||
'total_kelola',
|
||||
'total_daur_ulang',
|
||||
'sisa_sampah',
|
||||
];
|
||||
|
||||
/**
|
||||
* Relasi ke tabel users
|
||||
* One Sampah belongs to one User
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('sampah', function (Blueprint $table) {
|
||||
$table->tinyInteger('bulan')->after('tahun');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('sampah', function (Blueprint $table) {
|
||||
$table->dropColumn('bulan');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
After Width: | Height: | Size: 666 KiB |
|
After Width: | Height: | Size: 834 KiB |
|
After Width: | Height: | Size: 858 KiB |
|
After Width: | Height: | Size: 155 KiB |
|
After Width: | Height: | Size: 841 KiB |
|
After Width: | Height: | Size: 995 KiB |
|
After Width: | Height: | Size: 1.1 MiB |
|
After Width: | Height: | Size: 969 KiB |
|
After Width: | Height: | Size: 758 KiB |
|
After Width: | Height: | Size: 229 KiB |
|
After Width: | Height: | Size: 206 KiB |
|
After Width: | Height: | Size: 341 KiB |
|
After Width: | Height: | Size: 1.1 MiB |
|
After Width: | Height: | Size: 929 KiB |
|
After Width: | Height: | Size: 747 KiB |
|
After Width: | Height: | Size: 820 KiB |
|
After Width: | Height: | Size: 820 KiB |
|
After Width: | Height: | Size: 694 KiB |
|
After Width: | Height: | Size: 677 KiB |
|
After Width: | Height: | Size: 1016 KiB |
|
After Width: | Height: | Size: 820 KiB |
|
After Width: | Height: | Size: 893 KiB |
|
After Width: | Height: | Size: 263 KiB |
|
|
@ -1,124 +1,207 @@
|
|||
@extends('admin.template')
|
||||
|
||||
@section('title', 'Tambah Data Sampah Tahunan')
|
||||
@section('title', 'Tambah Data Sampah Bulanan')
|
||||
|
||||
@section('content')
|
||||
<div class="content-wrapper">
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-md-12 grid-margin stretch-card">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">Tambah Data Sampah Tahunan</h4>
|
||||
|
||||
<h4 class="card-title">Tambah Data Sampah Bulanan</h4>
|
||||
<p class="card-description">
|
||||
Form input data sampah harian per tahun (satuan dalam Ton)
|
||||
Form input data sampah per bulan (satuan Ton)
|
||||
</p>
|
||||
|
||||
<form action="{{ route('admin.sampah.store') }}" method="POST">
|
||||
<form action="{{ route('admin.sampah.store') }}" method="POST" id="formSampah">
|
||||
@csrf
|
||||
|
||||
<div class="form-group">
|
||||
<label>Tahun</label>
|
||||
|
||||
<input type="number" name="tahun"
|
||||
class="form-control @error('tahun') is-invalid @enderror"
|
||||
value="{{ old('tahun') }}"
|
||||
class="form-control @error('tahun') is-invalid @enderror" value="{{ old('tahun') }}"
|
||||
placeholder="Contoh: 2024">
|
||||
|
||||
@error('tahun')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label>Bulan</label>
|
||||
|
||||
<select name="bulan" class="form-control @error('bulan') is-invalid @enderror">
|
||||
<option value="">-- Pilih Bulan --</option>
|
||||
<option value="1">Januari</option>
|
||||
<option value="2">Februari</option>
|
||||
<option value="3">Maret</option>
|
||||
<option value="4">April</option>
|
||||
<option value="5">Mei</option>
|
||||
<option value="6">Juni</option>
|
||||
<option value="7">Juli</option>
|
||||
<option value="8">Agustus</option>
|
||||
<option value="9">September</option>
|
||||
<option value="10">Oktober</option>
|
||||
<option value="11">November</option>
|
||||
<option value="12">Desember</option>
|
||||
</select>
|
||||
|
||||
@error('bulan')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label>Total Sampah</label>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="text" step="0.01" name="total_sampah"
|
||||
id="total_sampah"
|
||||
class="form-control @error('total_sampah') is-invalid @enderror"
|
||||
value="{{ old('total_sampah') }}"
|
||||
placeholder="Total sampah dihasilkan">
|
||||
<input type="text" name="total_sampah" id="total_sampah"
|
||||
class="form-control angka @error('total_sampah') is-invalid @enderror"
|
||||
value="{{ old('total_sampah') }}" placeholder="Contoh: 7.500,89">
|
||||
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">Ton</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@error('total_sampah')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label>Total Sampah Dikelola</label>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="text" step="0.01" name="total_kelola"
|
||||
id="total_kelola"
|
||||
class="form-control @error('total_kelola') is-invalid @enderror"
|
||||
value="{{ old('total_kelola') }}"
|
||||
placeholder="Total sampah yang dikelola">
|
||||
<input type="text" name="total_kelola" id="total_kelola"
|
||||
class="form-control angka @error('total_kelola') is-invalid @enderror"
|
||||
value="{{ old('total_kelola') }}" placeholder="Contoh: 2.500,50">
|
||||
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">Ton</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@error('total_kelola')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label>Total Sampah Daur Ulang</label>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="text" step="0.01" name="total_daur_ulang"
|
||||
id="total_daur_ulang"
|
||||
class="form-control @error('total_daur_ulang') is-invalid @enderror"
|
||||
value="{{ old('total_daur_ulang') }}"
|
||||
placeholder="Total sampah yang didaur ulang">
|
||||
<input type="text" name="total_daur_ulang" id="total_daur_ulang"
|
||||
class="form-control angka @error('total_daur_ulang') is-invalid @enderror"
|
||||
value="{{ old('total_daur_ulang') }}" placeholder="Contoh: 1.200,25">
|
||||
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">Ton</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@error('total_daur_ulang')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label>Sisa Sampah</label>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="text" step="0.01" name="sisa_sampah"
|
||||
id="sisa_sampah"
|
||||
class="form-control" readonly>
|
||||
<input type="text" id="sisa_sampah" class="form-control" readonly>
|
||||
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">Ton</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<small class="text-muted">
|
||||
Sisa sampah dihitung otomatis
|
||||
</small>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<button type="submit" class="mr-2 btn btn-primary">
|
||||
Simpan
|
||||
</button>
|
||||
|
||||
<a href="{{ route('admin.sampah.index') }}" class="btn btn-light">
|
||||
Batal
|
||||
</a>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function hitungSisa() {
|
||||
let total = parseFloat(document.getElementById('total_sampah').value) || 0;
|
||||
let kelola = parseFloat(document.getElementById('total_kelola').value) || 0;
|
||||
let daur = parseFloat(document.getElementById('total_daur_ulang').value) || 0;
|
||||
|
||||
let sisa = total - (kelola + daur);
|
||||
document.getElementById('sisa_sampah').value = sisa >= 0 ? sisa : 0;
|
||||
<script>
|
||||
function formatRupiah(angka) {
|
||||
|
||||
angka = angka.replace(/[^,\d]/g, '');
|
||||
|
||||
let split = angka.split(',');
|
||||
let sisa = split[0].length % 3;
|
||||
let rupiah = split[0].substr(0, sisa);
|
||||
|
||||
let ribuan = split[0].substr(sisa).match(/\d{3}/gi);
|
||||
|
||||
if (ribuan) {
|
||||
let separator = sisa ? '.' : '';
|
||||
rupiah += separator + ribuan.join('.');
|
||||
}
|
||||
|
||||
document.getElementById('total_sampah').addEventListener('input', hitungSisa);
|
||||
document.getElementById('total_kelola').addEventListener('input', hitungSisa);
|
||||
document.getElementById('total_daur_ulang').addEventListener('input', hitungSisa);
|
||||
</script>
|
||||
rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
|
||||
|
||||
return rupiah;
|
||||
}
|
||||
|
||||
function toNumber(angka) {
|
||||
|
||||
return parseFloat(
|
||||
angka.replace(/\./g, '').replace(',', '.')
|
||||
) || 0;
|
||||
|
||||
}
|
||||
|
||||
function hitungSisa() {
|
||||
|
||||
let total = toNumber(document.getElementById('total_sampah').value);
|
||||
let kelola = toNumber(document.getElementById('total_kelola').value);
|
||||
let daur = toNumber(document.getElementById('total_daur_ulang').value);
|
||||
|
||||
let sisa = total - (kelola + daur);
|
||||
|
||||
document.getElementById('sisa_sampah').value =
|
||||
formatRupiah(sisa.toFixed(2).replace('.', ','));
|
||||
|
||||
}
|
||||
|
||||
document.querySelectorAll('.angka').forEach(function(input) {
|
||||
|
||||
input.addEventListener('keyup', function() {
|
||||
|
||||
this.value = formatRupiah(this.value);
|
||||
|
||||
hitungSisa();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
@extends('admin.template')
|
||||
|
||||
@section('title', 'Edit Data Sampah Tahunan')
|
||||
|
||||
@endsection
|
||||
@section('title', 'Edit Data Sampah Bulanan')
|
||||
|
||||
@section('content')
|
||||
<div class="content-wrapper">
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-md-12 grid-margin stretch-card">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">Edit Data Sampah Tahunan</h4>
|
||||
|
||||
<h4 class="card-title">Edit Data Sampah Bulanan</h4>
|
||||
<p class="card-description">
|
||||
Form edit data sampah harian per tahun (satuan Ton)
|
||||
Form edit data sampah per bulan (satuan Ton)
|
||||
</p>
|
||||
|
||||
<form action="{{ route('admin.sampah.update', $sampah->id_sampah) }}" method="POST">
|
||||
|
|
@ -21,86 +21,227 @@
|
|||
|
||||
<div class="form-group">
|
||||
<label>Tahun</label>
|
||||
|
||||
<input type="number" name="tahun"
|
||||
class="form-control @error('tahun') is-invalid @enderror"
|
||||
value="{{ old('tahun', $sampah->tahun) }}">
|
||||
|
||||
@error('tahun')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label>Bulan</label>
|
||||
|
||||
<select name="bulan" class="form-control @error('bulan') is-invalid @enderror">
|
||||
|
||||
<option value="">-- Pilih Bulan --</option>
|
||||
|
||||
<option value="1" {{ old('bulan', $sampah->bulan) == 1 ? 'selected' : '' }}>Januari
|
||||
</option>
|
||||
<option value="2" {{ old('bulan', $sampah->bulan) == 2 ? 'selected' : '' }}>
|
||||
Februari</option>
|
||||
<option value="3" {{ old('bulan', $sampah->bulan) == 3 ? 'selected' : '' }}>Maret
|
||||
</option>
|
||||
<option value="4" {{ old('bulan', $sampah->bulan) == 4 ? 'selected' : '' }}>April
|
||||
</option>
|
||||
<option value="5" {{ old('bulan', $sampah->bulan) == 5 ? 'selected' : '' }}>Mei
|
||||
</option>
|
||||
<option value="6" {{ old('bulan', $sampah->bulan) == 6 ? 'selected' : '' }}>Juni
|
||||
</option>
|
||||
<option value="7" {{ old('bulan', $sampah->bulan) == 7 ? 'selected' : '' }}>Juli
|
||||
</option>
|
||||
<option value="8" {{ old('bulan', $sampah->bulan) == 8 ? 'selected' : '' }}>
|
||||
Agustus</option>
|
||||
<option value="9" {{ old('bulan', $sampah->bulan) == 9 ? 'selected' : '' }}>
|
||||
September</option>
|
||||
<option value="10" {{ old('bulan', $sampah->bulan) == 10 ? 'selected' : '' }}>
|
||||
Oktober</option>
|
||||
<option value="11" {{ old('bulan', $sampah->bulan) == 11 ? 'selected' : '' }}>
|
||||
November</option>
|
||||
<option value="12" {{ old('bulan', $sampah->bulan) == 12 ? 'selected' : '' }}>
|
||||
Desember</option>
|
||||
|
||||
</select>
|
||||
|
||||
@error('bulan')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label>Total Sampah</label>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="number" step="0.01" name="total_sampah"
|
||||
class="form-control @error('total_sampah') is-invalid @enderror"
|
||||
value="{{ old('total_sampah', $sampah->total_sampah) }}">
|
||||
|
||||
<input type="text" name="total_sampah" id="total_sampah"
|
||||
class="form-control angka @error('total_sampah') is-invalid @enderror"
|
||||
value="{{ number_format($sampah->total_sampah, 2, ',', '.') }}">
|
||||
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">Ton</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@error('total_sampah')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label>Total Sampah Dikelola</label>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="number" step="0.01" name="total_kelola"
|
||||
class="form-control @error('total_kelola') is-invalid @enderror"
|
||||
value="{{ old('total_kelola', $sampah->total_kelola) }}">
|
||||
|
||||
<input type="text" name="total_kelola" id="total_kelola"
|
||||
class="form-control angka @error('total_kelola') is-invalid @enderror"
|
||||
value="{{ number_format($sampah->total_kelola, 2, ',', '.') }}">
|
||||
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">Ton</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@error('total_kelola')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label>Total Sampah Daur Ulang</label>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="number" step="0.01" name="total_daur_ulang"
|
||||
class="form-control @error('total_daur_ulang') is-invalid @enderror"
|
||||
value="{{ old('total_daur_ulang', $sampah->total_daur_ulang) }}">
|
||||
|
||||
<input type="text" name="total_daur_ulang" id="total_daur_ulang"
|
||||
class="form-control angka @error('total_daur_ulang') is-invalid @enderror"
|
||||
value="{{ number_format($sampah->total_daur_ulang, 2, ',', '.') }}">
|
||||
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">Ton</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@error('total_daur_ulang')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label>Sisa Sampah</label>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="number" step="0.01"
|
||||
class="form-control"
|
||||
value="{{ $sampah->sisa_sampah }}"
|
||||
readonly>
|
||||
|
||||
<input type="text" id="sisa_sampah" class="form-control"
|
||||
value="{{ number_format($sampah->sisa_sampah, 2, ',', '.') }}" readonly>
|
||||
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text">Ton</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<small class="text-muted">
|
||||
Sisa sampah dihitung otomatis oleh sistem
|
||||
Sisa sampah dihitung otomatis
|
||||
</small>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<button type="submit" class="mr-2 btn btn-primary">
|
||||
Simpan
|
||||
</button>
|
||||
|
||||
<a href="{{ route('admin.sampah.index') }}" class="btn btn-light">
|
||||
Batal
|
||||
</a>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
function formatAngka(angka) {
|
||||
|
||||
angka = angka.replace(/[^,\d]/g, '');
|
||||
|
||||
let split = angka.split(',');
|
||||
let sisa = split[0].length % 3;
|
||||
|
||||
let rupiah = split[0].substr(0, sisa);
|
||||
|
||||
let ribuan = split[0].substr(sisa).match(/\d{3}/gi);
|
||||
|
||||
if (ribuan) {
|
||||
|
||||
let separator = sisa ? '.' : '';
|
||||
|
||||
rupiah += separator + ribuan.join('.');
|
||||
|
||||
}
|
||||
|
||||
rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
|
||||
|
||||
return rupiah;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function toNumber(angka) {
|
||||
|
||||
return parseFloat(
|
||||
angka.replace(/\./g, '').replace(',', '.')
|
||||
) || 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function hitungSisa() {
|
||||
|
||||
let total = toNumber(document.getElementById('total_sampah').value);
|
||||
|
||||
let kelola = toNumber(document.getElementById('total_kelola').value);
|
||||
|
||||
let daur = toNumber(document.getElementById('total_daur_ulang').value);
|
||||
|
||||
let sisa = total - (kelola + daur);
|
||||
|
||||
document.getElementById('sisa_sampah').value =
|
||||
formatAngka(sisa.toFixed(2).replace('.', ','));
|
||||
|
||||
}
|
||||
|
||||
|
||||
document.querySelectorAll('.angka').forEach(function(input) {
|
||||
|
||||
input.addEventListener('keyup', function() {
|
||||
|
||||
this.value = formatAngka(this.value);
|
||||
|
||||
hitungSisa();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
@extends('admin.template')
|
||||
|
||||
@section('title', 'Data Sampah Tahunan')
|
||||
@section('title', 'Data Sampah Bulanan')
|
||||
|
||||
@section('content')
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-lg-12 grid-margin stretch-card">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
||||
<div class="mb-3 d-flex justify-content-between align-items-center">
|
||||
|
||||
<div>
|
||||
<h4 class="mb-0 card-title">Data Sampah</h4>
|
||||
<h4 class="mb-0 card-title">Data Sampah Bulanan</h4>
|
||||
<p class="mb-0 card-description">
|
||||
Daftar sampah harian per tahun
|
||||
Daftar data sampah per bulan
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
|
@ -21,15 +23,16 @@
|
|||
<i class="bi bi-plus-lg"></i> Tambah
|
||||
</a>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Tabel -->
|
||||
<div class="table-responsive">
|
||||
|
||||
<table class="table">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tahun</th>
|
||||
<th>Bulan</th>
|
||||
<th>Total Sampah</th>
|
||||
<th>Total Kelola</th>
|
||||
<th>Total Daur Ulang</th>
|
||||
|
|
@ -37,51 +40,74 @@
|
|||
<th>Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
@forelse ($sampah as $item)
|
||||
<tr>
|
||||
|
||||
<td>{{ $item->tahun }}</td>
|
||||
<td>{{ $item->total_sampah }}</td>
|
||||
<td>{{ $item->total_kelola }}</td>
|
||||
<td>{{ $item->total_daur_ulang }}</td>
|
||||
<td>{{ $item->sisa_sampah }}</td>
|
||||
|
||||
<td>
|
||||
{{ \Carbon\Carbon::create()->month($item->bulan)->translatedFormat('F') }}
|
||||
</td>
|
||||
|
||||
<td>{{ number_format($item->total_sampah, 2, ',', '.') }} Ton</td>
|
||||
<td>{{ number_format($item->total_kelola, 2, ',', '.') }} Ton</td>
|
||||
<td>{{ number_format($item->total_daur_ulang, 2, ',', '.') }} Ton</td>
|
||||
<td>{{ number_format($item->sisa_sampah, 2, ',', '.') }} Ton</td>
|
||||
|
||||
<td class="text-center">
|
||||
|
||||
<a href="{{ route('admin.sampah.edit', $item->id_sampah) }}"
|
||||
class="btn btn-warning btn-sm me-1">
|
||||
<i class="bi bi-pencil-square"></i>
|
||||
</a>
|
||||
|
||||
<form action="{{ route('admin.sampah.destroy', $item->id_sampah) }}" method="POST"
|
||||
class="form-hapus" style="display:inline;">
|
||||
<form action="{{ route('admin.sampah.destroy', $item->id_sampah) }}"
|
||||
method="POST" class="form-hapus" style="display:inline;">
|
||||
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
|
||||
<button type="submit" class="btn btn-danger btn-sm">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
@empty
|
||||
|
||||
<tr>
|
||||
<td colspan="5" class="text-center">
|
||||
<td colspan="7" class="text-center">
|
||||
Data sampah belum tersedia
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
document.querySelectorAll('.form-hapus').forEach(form => {
|
||||
|
||||
form.addEventListener('submit', function(e) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
|
|
@ -97,12 +123,17 @@ class="form-hapus" style="display:inline;">
|
|||
document.querySelector('.swal2-popup').style.fontFamily =
|
||||
'Nunito, sans-serif';
|
||||
}
|
||||
|
||||
}).then((result) => {
|
||||
|
||||
if (result.isConfirmed) {
|
||||
form.submit();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -118,4 +149,5 @@ class="form-hapus" style="display:inline;">
|
|||
});
|
||||
</script>
|
||||
@endif
|
||||
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -10,82 +10,101 @@
|
|||
<h1>Selamat Datang di <span>SIG TPS</span></h1>
|
||||
<p>Sistem Informasi Geografis Pemetaan Tempat Pembuangan Sampah di Kabupaten Nganjuk</p>
|
||||
<div class="d-flex">
|
||||
<a href="{{ route('user.sig-tps') }}" class="btn-get-started scrollto">Lihat Peta</a>
|
||||
<a href="#sebaranTPS" class="btn-get-started scrollto">Lihat Peta</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section><!-- /Hero Section -->
|
||||
|
||||
<!-- Featured Services Section -->
|
||||
<section id="featured-services" class="featured-services section">
|
||||
<section id="grafik-sampah" class="section">
|
||||
<div class="container">
|
||||
|
||||
<div class="container section-title" data-aos="fade-up">
|
||||
<h2>Sampah</h2>
|
||||
<p>Total sampah yang terkumpul di seluruh wilayah Kabupaten Nganjuk pada tahun
|
||||
{{ $sampah->tahun ?? 'Tahun Tidak Tersedia' }}</p>
|
||||
</div><!-- End Section Title -->
|
||||
|
||||
<div class="row gy-4">
|
||||
|
||||
<!-- Total Timbulan Sampah -->
|
||||
<div class="col-xl-3 col-md-6 d-flex" data-aos="fade-up" data-aos-delay="100">
|
||||
<div class="text-center service-item position-relative">
|
||||
<div class="icon">
|
||||
<i class="bi bi-trash2 icon"></i>
|
||||
</div>
|
||||
<h2>
|
||||
{{ number_format($sampah->total_sampah ?? 0, 2, ',', '.') }}
|
||||
</h2>
|
||||
<p>Total Timbulan Sampah (ton)</p>
|
||||
</div>
|
||||
<div class="section-title">
|
||||
<h2>Dashboard Sampah {{ $tahun }}</h2>
|
||||
<p>Statistik pengelolaan sampah Kabupaten Nganjuk</p>
|
||||
</div>
|
||||
|
||||
<!-- Total Sampah Dikelola -->
|
||||
<div class="col-xl-3 col-md-6 d-flex" data-aos="fade-up" data-aos-delay="200">
|
||||
<div class="text-center service-item position-relative">
|
||||
<div class="icon">
|
||||
<i class="bi bi-gear icon"></i>
|
||||
</div>
|
||||
<h2>
|
||||
{{ number_format($sampah->total_kelola ?? 0, 2, ',', '.') }}
|
||||
</h2>
|
||||
<p>Total Sampah Dikelola (ton)</p>
|
||||
</div>
|
||||
<!-- Rekap Tahunan -->
|
||||
<div class="mb-4 text-center row">
|
||||
|
||||
<div class="col-md-3">
|
||||
<h4>{{ number_format($rekap['timbulan'], 0, ',', '.') }}</h4>
|
||||
<p>Total Timbulan</p>
|
||||
</div>
|
||||
|
||||
<!-- Total Sampah Didaur Ulang -->
|
||||
<div class="col-xl-3 col-md-6 d-flex" data-aos="fade-up" data-aos-delay="300">
|
||||
<div class="text-center service-item position-relative">
|
||||
<div class="icon">
|
||||
<i class="bi bi-recycle icon"></i>
|
||||
</div>
|
||||
<h2>
|
||||
{{ number_format($sampah->total_daur_ulang ?? 0, 2, ',', '.') }}
|
||||
</h2>
|
||||
<p>Total Sampah Didaur Ulang (ton)</p>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<h4>{{ number_format($rekap['kelola'], 0, ',', '.') }}</h4>
|
||||
<p>Total Dikelola</p>
|
||||
</div>
|
||||
|
||||
<!-- Total Sisa Sampah -->
|
||||
<div class="col-xl-3 col-md-6 d-flex" data-aos="fade-up" data-aos-delay="400">
|
||||
<div class="text-center service-item position-relative">
|
||||
<div class="icon">
|
||||
<i class="bi bi-exclamation-triangle icon"></i>
|
||||
</div>
|
||||
<h2>
|
||||
{{ number_format($sampah->sisa_sampah ?? 0, 2, ',', '.') }}
|
||||
</h2>
|
||||
<p>Total Sisa Sampah (ton)</p>
|
||||
<div class="col-md-3">
|
||||
<h4>{{ number_format($rekap['daur'], 0, ',', '.') }}</h4>
|
||||
<p>Total Daur Ulang</p>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<h4>{{ number_format($rekap['sisa'], 0, ',', '.') }}</h4>
|
||||
<p>Total Sisa</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Grafik -->
|
||||
<div class="row justify-content-center">
|
||||
<div class="text-center col-md-8">
|
||||
<canvas id="grafikSampah"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
<!-- /Featured Services Section -->
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
|
||||
<script>
|
||||
const ctx = document.getElementById('grafikSampah');
|
||||
|
||||
new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: @json($bulan),
|
||||
datasets: [{
|
||||
label: 'Timbulan Sampah',
|
||||
data: @json($timbulan),
|
||||
backgroundColor: '#dc3545'
|
||||
},
|
||||
{
|
||||
label: 'Sampah Dikelola',
|
||||
data: @json($kelola),
|
||||
backgroundColor: '#0d6efd'
|
||||
},
|
||||
{
|
||||
label: 'Daur Ulang',
|
||||
data: @json($daur),
|
||||
backgroundColor: '#198754'
|
||||
},
|
||||
{
|
||||
label: 'Sisa Sampah',
|
||||
data: @json($sisa),
|
||||
backgroundColor: '#ffc107'
|
||||
}
|
||||
]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
plugins: {
|
||||
legend: {
|
||||
position: 'top'
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<!-- About Section -->
|
||||
|
|
@ -235,7 +254,12 @@ class="stretched-link">
|
|||
}
|
||||
</style>
|
||||
|
||||
<section class="section">
|
||||
<section class="section" id="sebaranTPS">
|
||||
<!-- Section Title -->
|
||||
<div class="container section-title" data-aos="fade-up">
|
||||
<h2>Peta Sebaran TPS</h2>
|
||||
<p>Peta interaktif yang menampilkan sebaran Tempat Pembuangan Sampah di Kabupaten Nganjuk.</p>
|
||||
</div><!-- End Section Title -->
|
||||
<div class="container">
|
||||
<div class="map-wrapper">
|
||||
<div class="map-action">
|
||||
|
|
|
|||