Upadte Fitur Detail Curas dan Detail Curanmor
This commit is contained in:
parent
d28c0bcab3
commit
0fc66d4909
|
@ -5,6 +5,7 @@
|
|||
use App\Models\Klaster;
|
||||
use App\Models\Curanmor;
|
||||
use App\Models\Kecamatan;
|
||||
use App\Models\Detail_Curanmor;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\KMeansService;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
@ -26,7 +27,7 @@ public function index()
|
|||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('admin.dashboardTambahCuranmor', ['kecamatans' => Kecamatan::all()], ['klasters' => Klaster::all()]);
|
||||
return view('admin.dashboardTambahCuranmor', ['kecamatans' => Kecamatan::all()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,14 +36,51 @@ public function create()
|
|||
public function store(Request $request)
|
||||
{
|
||||
try{
|
||||
$validateData = $request->validate([
|
||||
'kecamatan_id' =>'required|max:255|exists:kecamatans,id|unique:curanmors,kecamatan_id',
|
||||
'jumlah_curanmor' =>'required',
|
||||
'klaster_id' =>'required|max:255|exists:klasters,id',
|
||||
|
||||
$request->validate([
|
||||
'kecamatan_id' => 'required|exists:kecamatans,id',
|
||||
'jumlah_curanmor' => 'required|numeric',
|
||||
]);
|
||||
|
||||
$kecamatan_id = $request->kecamatan_id;
|
||||
$tambahan_curanmor = $request->jumlah_curanmor;
|
||||
|
||||
|
||||
$curanmor = Curanmor::where('kecamatan_id', $kecamatan_id)->first();
|
||||
|
||||
if ($curanmor) {
|
||||
$curanmor->jumlah_curanmor += $tambahan_curanmor;
|
||||
$curanmor->save();
|
||||
|
||||
$curanmor_id = $curanmor->id;
|
||||
} else {
|
||||
// Jika belum ada, bisa insert baru dulu (optional, sesuai kebutuhan)
|
||||
$curanmor = Curanmor::create([
|
||||
'kecamatan_id' => $kecamatan_id,
|
||||
'jumlah_curanmor' => $tambahan_curanmor,
|
||||
]);
|
||||
$curanmor_id = $curanmor->id;
|
||||
}
|
||||
Detail_Curanmor::create([
|
||||
'curanmor_id' => $curanmor_id,
|
||||
'tambahan_curanmor' => $tambahan_curanmor,
|
||||
'detailCuranmor_kecamatan_Id' => $kecamatan_id,
|
||||
|
||||
]);
|
||||
|
||||
Curanmor::create($validateData);
|
||||
$service = new KMeansService();
|
||||
$hasil = $service->hitungKMeansCuranmor();
|
||||
file_put_contents(storage_path('app/public/hasil_kmeans_curanmor.json'), json_encode($hasil));
|
||||
|
||||
// =====CODE TAMBAH SEBELUMNYA=========
|
||||
// $validateData = $request->validate([
|
||||
// 'kecamatan_id' =>'required|max:255|exists:kecamatans,id|unique:curanmors,kecamatan_id',
|
||||
// 'jumlah_curanmor' =>'required',
|
||||
// 'klaster_id' =>'required|max:255|exists:klasters,id',
|
||||
|
||||
// ]);
|
||||
|
||||
// Curanmor::create($validateData);
|
||||
return redirect('/dashboard/curanmor')->with('succes', 'Berhasil Menambahkan Data Curanmor Baru');
|
||||
}catch (\Exception $e){
|
||||
return redirect('/dashboard/curanmor')->with('error', 'Gagal Menambahkan Data Curanmor Baru');
|
||||
|
|
|
@ -2,9 +2,93 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Curanmor;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Detail_Curanmor;
|
||||
use App\Services\KMeansService;
|
||||
|
||||
class DetailCuranmorController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$detail_curanmor = Detail_Curanmor::orderBy('updated_at', 'desc')->get();
|
||||
|
||||
return view('admin.dashboardDetailCuranmor', compact('detail_curanmor'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Detail_Curanmor $detail_Curanmor)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Detail_Curanmor $detail_Curanmor)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Detail_Curanmor $detail_Curanmor)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$detail = Detail_Curanmor::findOrFail($id);
|
||||
|
||||
$curanmor = Curanmor::findOrFail($detail->curanmor_id);
|
||||
|
||||
$curanmor->jumlah_curanmor -= $detail->tambahan_curanmor;
|
||||
|
||||
// Pastikan tidak negatif
|
||||
if ($curanmor->jumlah_curanmor < 0) {
|
||||
$curanmor->jumlah_curanmor = 0;
|
||||
}
|
||||
|
||||
$curanmor->save();
|
||||
|
||||
$detail->delete();
|
||||
|
||||
$service = new KMeansService();
|
||||
$hasil = $service->hitungKMeansCuranmor();
|
||||
|
||||
// simpan hasil ke file json
|
||||
file_put_contents(storage_path('app/public/hasil_kmeans_curanmor.json'), json_encode($hasil));
|
||||
|
||||
return redirect('/dashboard/detail-curanmor')->with('succes', 'Data berhasil dihapus dan curanmor diperbarui.');
|
||||
} catch (\Exception $e) {
|
||||
return redirect('/dashboard/detail-curanmor')->with('error', 'Terjadi kesalahan Ketika Menghapus Data : ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,15 +2,98 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Curas;
|
||||
use App\Models\Detail_Curas;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\KMeansService;
|
||||
|
||||
class DetailCurasController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$detail_curas = Detail_Curas::orderBy('created_at')->get();
|
||||
$detail_curas = Detail_Curas::orderBy('updated_at', 'desc')->get();
|
||||
|
||||
return view('admin.dashboardDetailCuras', compact('detail_curas'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Detail_Curas $detail_Curas)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Detail_Curas $detail_Curas)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Detail_Curas $detail_Curas)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$detail = Detail_Curas::findOrFail($id);
|
||||
|
||||
// Ambil curas terkait
|
||||
$curas = Curas::findOrFail($detail->curas_id);
|
||||
|
||||
// Kurangi jumlah_curas
|
||||
$curas->jumlah_curas -= $detail->tambahan_curas;
|
||||
|
||||
// Pastikan tidak negatif
|
||||
if ($curas->jumlah_curas < 0) {
|
||||
$curas->jumlah_curas = 0;
|
||||
}
|
||||
|
||||
$curas->save(); // Simpan perubahan curas
|
||||
|
||||
// Hapus detail_curas
|
||||
$detail->delete();
|
||||
|
||||
$service = new KMeansService();
|
||||
$hasil = $service->hitungKMeansCuras();
|
||||
|
||||
// simpan hasil ke file json
|
||||
file_put_contents(storage_path('app/public/hasil_kmeans_curas.json'), json_encode($hasil));
|
||||
|
||||
return redirect('/dashboard/detail-curas')->with('succes', 'Data berhasil dihapus dan curas diperbarui.');
|
||||
} catch (\Exception $e) {
|
||||
return redirect('/dashboard/detail-curas')->with('error', 'Terjadi kesalahan Ketika Menghapus Data : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
|
|
||||
*/
|
||||
|
||||
'timezone' => env('APP_TIMEZONE', 'UTC'),
|
||||
'timezone' => env('APP_TIMEZONE', 'Asia/Jakarta'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
<x-layoutAdmin>
|
||||
<div class="content-page">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="d-flex flex-wrap align-items-center justify-content-between mb-4">
|
||||
<div>
|
||||
<h4 class="mb-3">Detail Kasus Curanmor Per Tanggal</h4>
|
||||
<p class="mb-0">Berikut ini merupakan rincian kasus Pencurian Kendaraan Bermotor (CURANMOR)
|
||||
yang dikelompokkan berdasarkan tanggal di inputkannya kasus CURANMOR yang terjadi</p>
|
||||
</div>
|
||||
</div>
|
||||
@if (session()->has('succes'))
|
||||
<div class="alert alert-success" role="alert">
|
||||
{{ session('succes') }}
|
||||
</div>
|
||||
@endif
|
||||
@if (session()->has('error'))
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{{ session('error') }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-lg-12">
|
||||
<div class="table-responsive rounded mb-3">
|
||||
<table class="data-table table mb-0 tbl-server-info">
|
||||
<thead class="bg-white text-uppercase">
|
||||
<tr class="ligth ligth-data">
|
||||
<th>Tanggal</th>
|
||||
<th>Nama Kecamatan</th>
|
||||
<th>Tambahan Kasus Curanmor</th>
|
||||
<th>Total Curanmor Per Kecamatan</th>
|
||||
<th>Hapus Update Kasus</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="ligth-body">
|
||||
@php
|
||||
$grouped = $detail_curanmor->groupBy(function($item) {
|
||||
return $item->created_at->format('Y-m-d');
|
||||
});
|
||||
@endphp
|
||||
@foreach($grouped as $tanggal => $items)
|
||||
@foreach($items as $index => $detail)
|
||||
<tr>
|
||||
@if ($index == 0)
|
||||
<td rowspan="{{ $items->count() }}">{{ \Carbon\Carbon::parse($tanggal)->translatedFormat('d F Y') }}</td>
|
||||
@endif
|
||||
<td class="text-left">{{ $detail->detailCuranmor_Kecamatan->nama_kecamatan }}</td>
|
||||
<td class="text-center">{{ $detail->tambahan_curanmor }}</td>
|
||||
<td class="text-center">{{ $detail->detailCuranmor_Curanmor->jumlah_curanmor }}</td>
|
||||
<td>
|
||||
<div class="d-flex align-items-center list-action">
|
||||
<form action="/dashboard/detail-curanmor/{{ $detail->id }}" method="post" class="d-inline">
|
||||
@method('delete')
|
||||
@csrf
|
||||
<button type="submit" class="badge bg-warning mr-2 border-0"><i class="ri-delete-bin-line mr-0"></i></button>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Page end -->
|
||||
</div>
|
||||
</div>
|
||||
</x-layoutAdmin>
|
|
@ -6,10 +6,9 @@
|
|||
<div class="d-flex flex-wrap align-items-center justify-content-between mb-4">
|
||||
<div>
|
||||
<h4 class="mb-3">Detail Kasus Curas Per Tanggal</h4>
|
||||
<p class="mb-0">Berikut ini merupakan rincian kasus Pencurian Dengan Kekerasan (CURAS) <br>
|
||||
yang dikelompokkan berdasarkan tanggal</p>
|
||||
<p class="mb-0">Berikut ini merupakan rincian kasus Pencurian Dengan Kekerasan (CURAS)
|
||||
yang dikelompokkan berdasarkan tanggal di inputkannya kasus CURAS yang terjadi</p>
|
||||
</div>
|
||||
<a href="/dashboard/curas/create" class="btn btn-primary add-list"><i class="las la-plus mr-3"></i>Tambah Kasus Curas</a>
|
||||
</div>
|
||||
@if (session()->has('succes'))
|
||||
<div class="alert alert-success" role="alert">
|
||||
|
@ -29,9 +28,9 @@
|
|||
<tr class="ligth ligth-data">
|
||||
<th>Tanggal</th>
|
||||
<th>Nama Kecamatan</th>
|
||||
<th>Tambahan Curas</th>
|
||||
<th>Jumlah Curas</th>
|
||||
<th>Hapus Kasus</th>
|
||||
<th>Tambahan Kasus Curas</th>
|
||||
<th>Total Curas Per Kecamatan</th>
|
||||
<th>Hapus Update Kasus</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="ligth-body">
|
||||
|
@ -46,12 +45,12 @@
|
|||
@if ($index == 0)
|
||||
<td rowspan="{{ $items->count() }}">{{ \Carbon\Carbon::parse($tanggal)->translatedFormat('d F Y') }}</td>
|
||||
@endif
|
||||
<td>{{ $detail->detailCuras_Kecamatan->nama_kecamatan }}</td>
|
||||
<td>{{ $detail->tambahan_curas }}</td>
|
||||
<td>{{ $detail->detailCuras_Curas->jumlah_curas }}</td>
|
||||
<td class="text-left">{{ $detail->detailCuras_Kecamatan->nama_kecamatan }}</td>
|
||||
<td class="text-center">{{ $detail->tambahan_curas }}</td>
|
||||
<td class="text-center">{{ $detail->detailCuras_Curas->jumlah_curas }}</td>
|
||||
<td>
|
||||
<div class="d-flex align-items-center list-action">
|
||||
<form action="/dashboard/curanmor/" method="post" class="d-inline">
|
||||
<form action="/dashboard/detail-curas/{{ $detail->id }}" method="post" class="d-inline">
|
||||
@method('delete')
|
||||
@csrf
|
||||
<button type="submit" class="badge bg-warning mr-2 border-0"><i class="ri-delete-bin-line mr-0"></i></button>
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
<th>Nama Kecamatan</th>
|
||||
<th>Jumlah Kasus Curanmor</th>
|
||||
<th>Klaster</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@foreach ( $curanmors as $curanmor )
|
||||
|
@ -53,18 +52,6 @@
|
|||
<td>{{ $curanmor->punyaKecamatanCuranmor->nama_kecamatan}}</td>
|
||||
<td>{{ $curanmor->jumlah_curanmor }}</td>
|
||||
<td style="background-color: {{ $curanmor->punyaKlasterCuranmor->warna }}">{{ $curanmor->punyaKlasterCuranmor->nama_klaster }}</td>
|
||||
<td>
|
||||
<div class="d-flex align-items-center list-action">
|
||||
<a class="badge bg-success mr-2" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit"
|
||||
href="/dashboard/curanmor/{{ $curanmor->id }}/edit"><i class="ri-pencil-line mr-0"></i></a>
|
||||
<form action="/dashboard/curanmor/{{ $curanmor->id }}" method="post" class="d-inline">
|
||||
@method('delete')
|
||||
@csrf
|
||||
<button type="submit" class="badge bg-warning mr-2 border-0"><i class="ri-delete-bin-line mr-0"></i></button>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@endforeach
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<form action="/dashboard/curanmor" data-toggle="validator" method="post">
|
||||
@csrf
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label>Nama Kecamatan *</label>
|
||||
<select class="selectpicker form-control" data-style="py-0" id="kecamatan_id" name="kecamatan_id">
|
||||
|
@ -31,18 +31,7 @@
|
|||
<input type="text" class="form-control" placeholder="Jumlah Kasus Curanmor" id="curanmor" name="jumlah_curanmor">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label>Klaster *</label>
|
||||
<select class="selectpicker form-control" data-style="py-0" name="klaster_id" id="klaster_id">
|
||||
<option value="" selected disabled>Pilih Klaster</option>
|
||||
@foreach ( $klasters as $klaster )
|
||||
<option value="{{ $klaster -> id }}" style="background-color: {{ $klaster->warna }}">{{ $klaster -> nama_klaster }}</option>
|
||||
@endforeach
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary mr-2">Tambah Data Kasus Curanmor</button>
|
||||
<button type="reset" class="btn btn-danger">Reset</button>
|
||||
|
|
|
@ -100,7 +100,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class=" {{ Request::is('dashboard/curas')||Request::is('dashboard/curas/create') ||Request::is('dashboard/curanmor/create') ||Request::is('dashboard/curanmor/create') ? 'active' : '' }}">
|
||||
<li class=" {{ Request::is('dashboard/curas')||Request::is('dashboard/curas/create') ||Request::is('dashboard/curanmor/create') ||Request::is('dashboard/curanmor/create') ||Request::is('dashboard/detail-curas') ||Request::is('dashboard/detail-curanmor') ? 'active' : '' }}">
|
||||
<a href="#people" class="collapsed" data-toggle="collapse" aria-expanded="false">
|
||||
<svg class="svg-icon" id="p-dash8" width="20" height="20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle><path d="M23 21v-2a4 4 0 0 0-3-3.87"></path><path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
|
||||
|
@ -116,6 +116,11 @@
|
|||
<i class="las la-minus"></i><span>Kasus Curas</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="">
|
||||
<a href="/dashboard/detail-curas">
|
||||
<i class="las la-minus"></i><span>Detail Kasus Curas</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="">
|
||||
<a href="/dashboard/curas/create">
|
||||
<i class="las la-minus"></i><span>Tambah Kasus Curas</span>
|
||||
|
@ -127,6 +132,11 @@
|
|||
<i class="las la-minus"></i><span>Kasus Curanmor</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="">
|
||||
<a href="/dashboard/detail-curanmor">
|
||||
<i class="las la-minus"></i><span>Detail Kasus Curanmor</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="">
|
||||
<a href="/dashboard/curanmor/create">
|
||||
<i class="las la-minus"></i><span>Tambah Kasus Curanmor</span>
|
||||
|
|
|
@ -10,14 +10,16 @@
|
|||
use App\Http\Controllers\KecamatanController;
|
||||
use App\Http\Controllers\DetailCurasController;
|
||||
use App\Http\Controllers\hasilIterasiController;
|
||||
use App\Http\Controllers\DetailCuranmorController;
|
||||
|
||||
Route::get('/', function () {
|
||||
return view('landing');
|
||||
});
|
||||
|
||||
|
||||
Route::resource('/dashboard/detail-curas', DetailCurasController::class)->middleware('auth');
|
||||
Route::resource('/dashboard/detail-curanmor', DetailCuranmorController::class)->middleware('auth');
|
||||
|
||||
Route::get('/detail', [DetailCurasController::class, 'index'])->name('login');
|
||||
|
||||
Route::get('/blank', function () {
|
||||
return view('admin.dashboardBlank');
|
||||
|
|
Loading…
Reference in New Issue