Upadate detailcuras finish, kurang tampilan
This commit is contained in:
parent
16daed6b6f
commit
d28c0bcab3
|
@ -5,6 +5,7 @@
|
||||||
use App\Models\Curas;
|
use App\Models\Curas;
|
||||||
use App\Models\Klaster;
|
use App\Models\Klaster;
|
||||||
use App\Models\Kecamatan;
|
use App\Models\Kecamatan;
|
||||||
|
use App\Models\Detail_Curas;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Services\KMeansService;
|
use App\Services\KMeansService;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
@ -36,15 +37,48 @@ public function create()
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
$validateData = $request->validate([
|
|
||||||
'kecamatan_id' =>'required|max:255|exists:kecamatans,id|unique:curas,kecamatan_id',
|
$request->validate([
|
||||||
'jumlah_curas' =>'required',
|
'kecamatan_id' => 'required|exists:kecamatans,id',
|
||||||
'klaster_id' =>'required|max:255|exists:klasters,id',
|
'jumlah_curas' => 'required|numeric',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$kecamatan_id = $request->kecamatan_id;
|
||||||
|
$tambahan_curas = $request->jumlah_curas;
|
||||||
|
|
||||||
|
// 2. Ambil data curas berdasarkan kecamatan_id
|
||||||
|
$curas = Curas::where('kecamatan_id', $kecamatan_id)->first();
|
||||||
|
|
||||||
|
if ($curas) {
|
||||||
|
// 3. Update jumlah_curas dengan nilai yang baru
|
||||||
|
$curas->jumlah_curas += $tambahan_curas;
|
||||||
|
$curas->save();
|
||||||
|
|
||||||
|
$curas_id = $curas->id;
|
||||||
|
} else {
|
||||||
|
// Jika belum ada, bisa insert baru dulu (optional, sesuai kebutuhan)
|
||||||
|
$curas = Curas::create([
|
||||||
|
'kecamatan_id' => $kecamatan_id,
|
||||||
|
'jumlah_curas' => $tambahan_curas,
|
||||||
|
]);
|
||||||
|
$curas_id = $curas->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Tambah data ke tabel detail_curas
|
||||||
|
Detail_Curas::create([
|
||||||
|
'curas_id' => $curas_id,
|
||||||
|
'tambahan_curas' => $tambahan_curas,
|
||||||
|
'detailCuras_kecamatan_Id' => $kecamatan_id,
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Curas::create($validateData);
|
$service = new KMeansService();
|
||||||
return redirect('/dashboard/curas')->with('succes', 'Berhasil Menambahkan Data Curas Baru');
|
$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/curas')->with('succes', 'Data curas berhasil ditambahkan.');
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
return redirect('/dashboard/curas')->with('error', 'Gagal Menambahkan Data Curas Baru');
|
return redirect('/dashboard/curas')->with('error', 'Gagal Menambahkan Data Curas Baru');
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class DetailCuranmorController extends Controller
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Detail_Curas;
|
||||||
|
|
||||||
|
class DetailCurasController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$detail_curas = Detail_Curas::orderBy('created_at')->get();
|
||||||
|
|
||||||
|
return view('admin.dashboardDetailCuras', compact('detail_curas'));
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,32 +27,28 @@
|
||||||
<table class="data-table table mb-0 tbl-server-info">
|
<table class="data-table table mb-0 tbl-server-info">
|
||||||
<thead class="bg-white text-uppercase">
|
<thead class="bg-white text-uppercase">
|
||||||
<tr class="ligth ligth-data">
|
<tr class="ligth ligth-data">
|
||||||
<th>
|
|
||||||
<div class="checkbox d-inline-block">
|
|
||||||
<input type="checkbox" class="checkbox-input" id="checkbox1">
|
|
||||||
<label for="checkbox1" class="mb-0"></label>
|
|
||||||
</div>
|
|
||||||
</th>
|
|
||||||
<th>No</th>
|
|
||||||
<th>Tanggal</th>
|
<th>Tanggal</th>
|
||||||
<th>Tambahan Kasus Curas</th>
|
|
||||||
<th>Nama Kecamatan</th>
|
<th>Nama Kecamatan</th>
|
||||||
|
<th>Tambahan Curas</th>
|
||||||
|
<th>Jumlah Curas</th>
|
||||||
<th>Hapus Kasus</th>
|
<th>Hapus Kasus</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{{-- @foreach ( $curases as $curas ) --}}
|
|
||||||
<tbody class="ligth-body">
|
<tbody class="ligth-body">
|
||||||
|
@php
|
||||||
|
$grouped = $detail_curas->groupBy(function($item) {
|
||||||
|
return $item->created_at->format('Y-m-d');
|
||||||
|
});
|
||||||
|
@endphp
|
||||||
|
@foreach($grouped as $tanggal => $items)
|
||||||
|
@foreach($items as $index => $detail)
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
@if ($index == 0)
|
||||||
<div class="checkbox d-inline-block">
|
<td rowspan="{{ $items->count() }}">{{ \Carbon\Carbon::parse($tanggal)->translatedFormat('d F Y') }}</td>
|
||||||
<input type="checkbox" class="checkbox-input" id="checkbox2">
|
@endif
|
||||||
<label for="checkbox2" class="mb-0"></label>
|
<td>{{ $detail->detailCuras_Kecamatan->nama_kecamatan }}</td>
|
||||||
</div>
|
<td>{{ $detail->tambahan_curas }}</td>
|
||||||
</td>
|
<td>{{ $detail->detailCuras_Curas->jumlah_curas }}</td>
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
<td>
|
<td>
|
||||||
<div class="d-flex align-items-center list-action">
|
<div class="d-flex align-items-center list-action">
|
||||||
<form action="/dashboard/curanmor/" method="post" class="d-inline">
|
<form action="/dashboard/curanmor/" method="post" class="d-inline">
|
||||||
|
@ -64,8 +60,9 @@
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
{{-- @endforeach --}}
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,14 +6,14 @@
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header d-flex justify-content-between">
|
<div class="card-header d-flex justify-content-between">
|
||||||
<div class="header-title">
|
<div class="header-title">
|
||||||
<h4 class="card-title">Tambah Data Kasus Pencurian Dengan Kekerasan ( CURAS )</h4>
|
<h4 class="card-title">Tambah Data Kasus CURAS Hari Ini</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form action="/dashboard/curas" data-toggle="validator" method="post">
|
<form action="/dashboard/curas" data-toggle="validator" method="post">
|
||||||
@csrf
|
@csrf
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Nama Kecamatan *</label>
|
<label>Nama Kecamatan *</label>
|
||||||
<select class="selectpicker form-control" data-style="py-0" id="kecamatan_id" name="kecamatan_id">
|
<select class="selectpicker form-control" data-style="py-0" id="kecamatan_id" name="kecamatan_id">
|
||||||
|
@ -21,7 +21,6 @@
|
||||||
@foreach ( $kecamatans as $kecamatan )
|
@foreach ( $kecamatans as $kecamatan )
|
||||||
<option value="{{ $kecamatan -> id }}" >{{ $kecamatan -> nama_kecamatan }}</option>
|
<option value="{{ $kecamatan -> id }}" >{{ $kecamatan -> nama_kecamatan }}</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -31,18 +30,6 @@
|
||||||
<input type="text" class="form-control" placeholder="Jumlah Kasus Curas" id="jumlah_curas" name="jumlah_curas">
|
<input type="text" class="form-control" placeholder="Jumlah Kasus Curas" id="jumlah_curas" name="jumlah_curas">
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary mr-2">Tambah Data Kasus Curas</button>
|
<button type="submit" class="btn btn-primary mr-2">Tambah Data Kasus Curas</button>
|
||||||
<button type="reset" class="btn btn-danger">Reset</button>
|
<button type="reset" class="btn btn-danger">Reset</button>
|
||||||
|
|
|
@ -8,17 +8,17 @@
|
||||||
use App\Http\Controllers\CuranmorController;
|
use App\Http\Controllers\CuranmorController;
|
||||||
use App\Http\Controllers\dashboardController;
|
use App\Http\Controllers\dashboardController;
|
||||||
use App\Http\Controllers\KecamatanController;
|
use App\Http\Controllers\KecamatanController;
|
||||||
|
use App\Http\Controllers\DetailCurasController;
|
||||||
use App\Http\Controllers\hasilIterasiController;
|
use App\Http\Controllers\hasilIterasiController;
|
||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return view('landing');
|
return view('landing');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('/detail', function () {
|
|
||||||
return view('admin.dashboardDetailCuras');
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
Route::get('/detail', [DetailCurasController::class, 'index'])->name('login');
|
||||||
|
|
||||||
Route::get('/blank', function () {
|
Route::get('/blank', function () {
|
||||||
return view('admin.dashboardBlank');
|
return view('admin.dashboardBlank');
|
||||||
});
|
});
|
||||||
|
@ -38,6 +38,8 @@
|
||||||
Route::resource('/dashboard/curas', CurasController::class)->middleware('auth');
|
Route::resource('/dashboard/curas', CurasController::class)->middleware('auth');
|
||||||
Route::resource('/dashboard/curanmor', CuranmorController::class) ->parameters(['data-curanmor' => 'curanmor'])->middleware('auth');
|
Route::resource('/dashboard/curanmor', CuranmorController::class) ->parameters(['data-curanmor' => 'curanmor'])->middleware('auth');
|
||||||
Route::resource('/dashboard/klaster', KlasterController::class) ->parameters(['data-klaster' => 'klaster'])->middleware('auth');
|
Route::resource('/dashboard/klaster', KlasterController::class) ->parameters(['data-klaster' => 'klaster'])->middleware('auth');
|
||||||
|
|
||||||
Route::get('/dashboard/iterasiCuras', [hasilIterasiController::class, 'iterasiCuras'])->middleware('auth');
|
Route::get('/dashboard/iterasiCuras', [hasilIterasiController::class, 'iterasiCuras'])->middleware('auth');
|
||||||
|
|
||||||
Route::get('/kmeans-curas', [KmeansController::class, 'KMeansCuras']);
|
Route::get('/kmeans-curas', [KmeansController::class, 'KMeansCuras']);
|
||||||
Route::get('/kmeans-curanmor', [KmeansController::class, 'KMeansCuranmor']);
|
Route::get('/kmeans-curanmor', [KmeansController::class, 'KMeansCuranmor']);
|
||||||
|
|
Loading…
Reference in New Issue