petani lahan
This commit is contained in:
@@ -5,12 +5,17 @@ namespace App\Http\Controllers\Web\Produktivitas;
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
use App\Models\Pertanian\Petani;
|
use App\Models\Pertanian\Petani;
|
||||||
use App\Models\Pertanian\Lahan;
|
use App\Models\Pertanian\Lahan;
|
||||||
use App\Models\Wilayah\DesaKelurahan;
|
use App\Models\Wilayah\DesaKelurahan;
|
||||||
use App\Models\Wilayah\Provinsi;
|
use App\Models\Wilayah\Provinsi;
|
||||||
use App\Models\Pertanian\Komoditas;
|
use App\Models\Pertanian\Komoditas;
|
||||||
|
use App\Models\Pertanian\Tanaman;
|
||||||
|
|
||||||
class PetaniLahanController extends Controller
|
class PetaniLahanController extends Controller
|
||||||
{
|
{
|
||||||
@@ -24,7 +29,12 @@ class PetaniLahanController extends Controller
|
|||||||
|
|
||||||
$lahan = Lahan::where('petani_id', $petaniId)
|
$lahan = Lahan::where('petani_id', $petaniId)
|
||||||
->orderBy('created_at', 'desc')
|
->orderBy('created_at', 'desc')
|
||||||
->paginate($request->per_page ?? 10);
|
->get();
|
||||||
|
|
||||||
|
if ($lahan->count() > 0) {
|
||||||
|
return redirect()->route('petani.lahan-tanaman.edit', [$petaniId, $lahan->first()->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return view('produktivitas.petani.lahan.index', compact('petani', 'lahan'));
|
return view('produktivitas.petani.lahan.index', compact('petani', 'lahan'));
|
||||||
}
|
}
|
||||||
@@ -39,7 +49,7 @@ class PetaniLahanController extends Controller
|
|||||||
|
|
||||||
$lahan = Lahan::where('petani_id', $petaniId)
|
$lahan = Lahan::where('petani_id', $petaniId)
|
||||||
->orderBy('created_at', 'desc')
|
->orderBy('created_at', 'desc')
|
||||||
->paginate($request->per_page ?? 10);
|
->get();
|
||||||
|
|
||||||
$provinsi = Provinsi::orderBy('kode', 'asc')->get();
|
$provinsi = Provinsi::orderBy('kode', 'asc')->get();
|
||||||
|
|
||||||
@@ -48,28 +58,98 @@ class PetaniLahanController extends Controller
|
|||||||
return view('produktivitas.petani.lahan.add', compact('petani', 'lahan', 'provinsi', 'komoditas'));
|
return view('produktivitas.petani.lahan.add', compact('petani', 'lahan', 'provinsi', 'komoditas'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function store($petaniId, Request $request)
|
||||||
* Store a newly created resource in storage.
|
|
||||||
*/
|
|
||||||
public function store(Request $request)
|
|
||||||
{
|
{
|
||||||
//
|
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||||
|
abort(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
$petani = Petani::findOrFail($petaniId);
|
||||||
* Display the specified resource.
|
|
||||||
*/
|
$validated = $request->validate([
|
||||||
public function show(string $id)
|
'nama' => ['nullable', 'string', 'max:255'],
|
||||||
{
|
'status_kepemilikan' => ['nullable', 'string', 'max:255'],
|
||||||
//
|
'profile_id' => ['nullable'],
|
||||||
|
'petani_id' => ['nullable'],
|
||||||
|
'keluarga_pengelola_id' => ['nullable'],
|
||||||
|
'adat_pemilik_id' => ['nullable'],
|
||||||
|
'desa_kelurahan_id' => ['nullable'],
|
||||||
|
'luas_lahan' => ['required', 'numeric'],
|
||||||
|
'path' => ['nullable', 'string'],
|
||||||
|
'komoditas_id' => ['required', 'exists:master_komoditas,id'],
|
||||||
|
'jenis_komoditas_id' => ['required', 'exists:jenis_komoditas,id'],
|
||||||
|
'varietas_id' => ['nullable', 'exists:master_varietas,id'],
|
||||||
|
'jumlah_tanaman' => ['required', 'numeric'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$komoditas = Komoditas::where('id', $request->komoditas_id)->first();
|
||||||
|
$lahanCount = Lahan::where('petani_id', $petaniId)
|
||||||
|
->count();
|
||||||
|
|
||||||
|
$lahan = Lahan::create([...$validated,
|
||||||
|
'nama' => 'Lahan ' . $komoditas->nama . ' #' . ($lahanCount + 1),
|
||||||
|
'uid' => 'LHN-' . $petani->uid . '-' . strtoupper(Str::random(10)),
|
||||||
|
'petani_id' => $petaniId,
|
||||||
|
'created_by' => auth()->id(),
|
||||||
|
'updated_by' => auth()->id()]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($lahan) {
|
||||||
|
$data = collect(range(1, $lahan->jumlah_tanaman))->map(function ($i) use ($lahan, $komoditas) {
|
||||||
|
return [
|
||||||
|
'lahan_id' => $lahan->id,
|
||||||
|
'komoditas_id' => $lahan->komoditas_id,
|
||||||
|
'jenis_komoditas_id' => $lahan->jenis_komoditas_id,
|
||||||
|
'varietas_id' => $lahan->varietas_id,
|
||||||
|
'petani_id' => $lahan->petani_id,
|
||||||
|
'nama' => 'Tanaman ' . $komoditas->nama . ' #' . $i,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
$data->chunk(500)->each(function ($chunk) {
|
||||||
|
Tanaman::insert($chunk->toArray());
|
||||||
|
});
|
||||||
|
|
||||||
|
return redirect()->route('petani.lahan-tanaman.index', $petaniId)->with('success', 'Lahan berhasil ditambahkan.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function show(string $petaniId, string $id)
|
||||||
* Show the form for editing the specified resource.
|
|
||||||
*/
|
|
||||||
public function edit(string $id)
|
|
||||||
{
|
{
|
||||||
//
|
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$petani = Petani::findOrFail($petaniId);
|
||||||
|
$lahan = Lahan::where('petani_id', $petaniId)
|
||||||
|
->orderBy('created_at', 'desc')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$lahanSelected = Lahan::where('petani_id', $petaniId)->findOrFail($id);
|
||||||
|
|
||||||
|
$provinsi = Provinsi::orderBy('kode', 'asc')->get();
|
||||||
|
|
||||||
|
return view('produktivitas.petani.lahan.view', compact('lahan', 'lahanSelected', 'petani', 'provinsi'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(string $petaniId, string $id)
|
||||||
|
{
|
||||||
|
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$petani = Petani::findOrFail($petaniId);
|
||||||
|
$lahan = Lahan::where('petani_id', $petaniId)
|
||||||
|
->orderBy('created_at', 'desc')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$lahanSelected = Lahan::where('petani_id', $petaniId)->findOrFail($id);
|
||||||
|
|
||||||
|
$komoditas = Komoditas::all();
|
||||||
|
|
||||||
|
$provinsi = Provinsi::orderBy('kode', 'asc')->get();
|
||||||
|
|
||||||
|
return view('produktivitas.petani.lahan.edit', compact('lahan', 'lahanSelected', 'petani', 'komoditas', 'provinsi'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ use App\Models\Pertanian\Adat;
|
|||||||
use App\Enums\StatusLahan;
|
use App\Enums\StatusLahan;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use App\Models\Pertanian\Komoditas;
|
||||||
|
use App\Models\Master\JenisKomoditas;
|
||||||
|
use App\Models\Master\Varietas;
|
||||||
|
|
||||||
class Lahan extends Model
|
class Lahan extends Model
|
||||||
{
|
{
|
||||||
@@ -28,6 +31,11 @@ class Lahan extends Model
|
|||||||
'desa_kelurahan_id',
|
'desa_kelurahan_id',
|
||||||
'path',
|
'path',
|
||||||
'luas_lahan',
|
'luas_lahan',
|
||||||
|
'komoditas_id',
|
||||||
|
'jenis_komoditas_id',
|
||||||
|
'varietas_id',
|
||||||
|
'jumlah_tanaman',
|
||||||
|
'petani_id',
|
||||||
'created_by',
|
'created_by',
|
||||||
'updated_by',
|
'updated_by',
|
||||||
'deleted_by',
|
'deleted_by',
|
||||||
@@ -57,4 +65,24 @@ class Lahan extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Tanaman::class, 'lahan_id');
|
return $this->hasMany(Tanaman::class, 'lahan_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function petani(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Profile::class, 'petani_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function komoditas(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Komoditas::class, 'komoditas_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jenisKomoditas(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(JenisKomoditas::class, 'jenis_komoditas_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function varietas(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Varietas::class, 'varietas_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ return new class extends Migration
|
|||||||
Schema::table('petani', function (Blueprint $table) {
|
Schema::table('petani', function (Blueprint $table) {
|
||||||
$table->foreignId('profile_id')->nullable()->constrained('profiles')->onDelete('set null');
|
$table->foreignId('profile_id')->nullable()->constrained('profiles')->onDelete('set null');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Schema::table('map_petani', function (Blueprint $table) {
|
||||||
|
$table->foreignId('petani_id')->nullable()->constrained('petani')->onDelete('set null');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link {{ request()->routeIs('petani.lahan-tanaman.index') ? 'active' : '' }}" href="{{ route('petani.lahan-tanaman.index', $petani->id) }}">
|
<a class="nav-link {{ request()->routeIs('petani.lahan-tanaman.*') ? 'active' : '' }}" href="{{ route('petani.lahan-tanaman.index', $petani->id) }}">
|
||||||
<i class="icon-base ti tabler-user-check me-1_5 icon-sm"></i>Lahan & Tanaman
|
<i class="icon-base ti tabler-user-check me-1_5 icon-sm"></i>Lahan & Tanaman
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
<ul class="nav nav-align-left nav-pills flex-column">
|
<ul class="nav nav-align-left nav-pills flex-column">
|
||||||
@foreach($lahan as $item)
|
@foreach($lahan as $item)
|
||||||
<li class="nav-item mb-1">
|
<li class="nav-item mb-1">
|
||||||
<a class="nav-link" href="{{ route('petani.lahan-tanaman.edit', ['petani' => $petani->id, 'id' => $item->id]) }}">
|
<a class="nav-link" href="{{ route('petani.lahan-tanaman.edit', ['petani' => $petani->id, 'lahan_tanaman' => $item->id]) }}">
|
||||||
<span class="align-middle">
|
<span class="align-middle">
|
||||||
<i class="icon-base ti tabler-building-store icon-sm me-1_5"></i>{{ $item->nama }}
|
<i class="icon-base ti tabler-building-store icon-sm me-1_5"></i>{{ $item->nama }}
|
||||||
</span>
|
</span>
|
||||||
@@ -60,9 +60,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="col-12 col-lg-10 col-md-9 pt-6 pt-lg-0">
|
||||||
<form id="petani-lahan-tanaman" method="POST" action="{{ route('petani.lahan-tanaman.store', ['petani' => $petani->id]) }}">
|
<form id="petani-lahan-tanaman" method="POST" action="{{ route('petani.lahan-tanaman.store', ['petani' => $petani->id]) }}">
|
||||||
@csrf
|
@csrf
|
||||||
<div class="col-12 col-lg-10 col-md-9 pt-6 pt-lg-0">
|
<input type="hidden" name="status_kepemilikan" value="sendiri">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6 mb-4">
|
<div class="col-lg-6 mb-4">
|
||||||
<h6 class="mb-3">Data Lahan dan Komoditas</h6>
|
<h6 class="mb-3">Data Lahan dan Komoditas</h6>
|
||||||
@@ -174,13 +176,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,510 @@
|
|||||||
|
@extends('layout.main')
|
||||||
|
|
||||||
|
@push('style')
|
||||||
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.css" />
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#map {
|
||||||
|
height: 600px;
|
||||||
|
width: 100%;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@endpush
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="container-xxl flex-grow-1 container-p-y">
|
||||||
|
@if ($errors->any())
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<ul class="mb-0">
|
||||||
|
@foreach ($errors->all() as $error)
|
||||||
|
<li>{{ $error }}</li>
|
||||||
|
@endforeach
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<!-- PROFIL PETANI -->
|
||||||
|
|
||||||
|
<div class="col-md-12">
|
||||||
|
|
||||||
|
@include('produktivitas.petani.header', ['petani' => $petani])
|
||||||
|
|
||||||
|
<div class="card mb-6">
|
||||||
|
<div class="card-body pt-12">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12 col-lg-2 col-md-3">
|
||||||
|
<div class="d-flex justify-content-between flex-column mb-4 mb-md-0">
|
||||||
|
<ul class="nav nav-align-left nav-pills flex-column">
|
||||||
|
@foreach($lahan as $item)
|
||||||
|
<li class="nav-item mb-1">
|
||||||
|
<a class="nav-link {{ $item->id == $lahanSelected->id ? 'active' : '' }}" href="{{ route('petani.lahan-tanaman.edit', ['petani' => $petani->id, 'lahan_tanaman' => $item->id]) }}">
|
||||||
|
<span class="align-middle">
|
||||||
|
<i class="icon-base ti tabler-building-store icon-sm me-1_5"></i>{{ $item->nama }}
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
@endforeach
|
||||||
|
<li class="nav-item mb-1">
|
||||||
|
<a class="nav-link aive" href="{{ route('petani.lahan-tanaman.create', ['petani' => $petani->id]) }}">
|
||||||
|
<span class="align-middle">
|
||||||
|
<i class="icon-base ti tabler-plus icon-sm me-1_5"></i>Tambah Lahan
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="col-12 col-lg-10 col-md-9 pt-6 pt-lg-0">
|
||||||
|
<form id="petani-lahan-tanaman" method="POST" action="{{ route('petani.lahan-tanaman.store', ['petani' => $petani->id]) }}">
|
||||||
|
@csrf
|
||||||
|
<input type="hidden" name="status_kepemilikan" value="sendiri">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-6 mb-4">
|
||||||
|
<h6 class="mb-3">Data Lahan dan Komoditas</h6>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3 form-control-validation">
|
||||||
|
<label class="form-label">Luas Lahan (m2) <span class="text-danger">*</span></label>
|
||||||
|
<input type="number" step="0.01" id="luas_lahan" name="luas_lahan" class="form-control @error('luas_lahan') is-invalid @enderror" placeholder="Contoh: 1.5" required
|
||||||
|
value="{{ old('luas_lahan', $lahanSelected->luas_lahan) }}" />
|
||||||
|
@error('luas_lahan')<div class="error invalid-feedback">{{ $message }}</div>@enderror
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3 form-control-validation">
|
||||||
|
<label class="form-label">Komoditas Utama <span class="text-danger">*</span></label>
|
||||||
|
<select id="komoditas_id" name="komoditas_id" class="form-select @error('komoditas_id') is-invalid @enderror">
|
||||||
|
<option value="">Pilih Komoditas</option>
|
||||||
|
@foreach($komoditas as $k)
|
||||||
|
<option value="{{ $k->id }}" {{ old('komoditas_id', $lahanSelected->komoditas_id) == $k->id ? 'selected' : '' }}>{{ $k->nama }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
@error('komoditas_id')<div class="error invalid-feedback">{{ $message }}</div>@enderror
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3 form-control-validation">
|
||||||
|
<label class="form-label">Jenis Komoditas Utama <span class="text-danger">*</span></label>
|
||||||
|
<select id="jenis_komoditas_id" name="jenis_komoditas_id" class="form-select @error('jenis_komoditas_id') is-invalid @enderror" disabled>
|
||||||
|
@if(old('jenis_komoditas_id', $lahanSelected->jenis_komoditas_id))
|
||||||
|
<option value="{{ old('jenis_komoditas_id', $lahanSelected->jenis_komoditas_id) }}">{{ $lahanSelected->jenisKomoditas->nama }}</option>
|
||||||
|
@endif
|
||||||
|
</select>
|
||||||
|
@error('jenis_komoditas_id')<div class="error invalid-feedback">{{ $message }}</div>@enderror
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3 form-control-validation">
|
||||||
|
<label class="form-label">Varietas Umum <span class="text-danger">*</span></label>
|
||||||
|
<select id="varietas_id" name="varietas_id" class="form-select @error('varietas_id') is-invalid @enderror" disabled>
|
||||||
|
@if(old('varietas_id', $lahanSelected->varietas_id))
|
||||||
|
<option value="{{ old('varietas_id', $lahanSelected->varietas_id) }}">{{ $lahanSelected->varietas->nama }}</option>
|
||||||
|
@endif
|
||||||
|
</select>
|
||||||
|
@error('varietas_id')<div class="error invalid-feedback">{{ $message }}</div>@enderror
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3 form-control-validation">
|
||||||
|
<label class="form-label">Jumlah Tanaman <span class="text-danger">*</span></label>
|
||||||
|
<input type="number" name="jumlah_tanaman" class="form-control @error('jumlah_tanaman') is-invalid @enderror" placeholder="Contoh: 1" required />
|
||||||
|
@error('jumlah_tanaman')<div class="error invalid-feedback">{{ $message }}</div>@enderror
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr class="my-4">
|
||||||
|
<h6 class="mb-3 text-primary"><i class="ti tabler-map-pin me-1"></i> Lokasi Wilayah</h6>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3 form-control-validation">
|
||||||
|
<label class="form-label">Provinsi <span class="text-danger">*</span></label>
|
||||||
|
<select name="provinsi_id" id="provinsi_id" class="form-select @error('provinsi_id') is-invalid @enderror" required>
|
||||||
|
<option value="">Pilih Provinsi</option>
|
||||||
|
@foreach($provinsi as $p)
|
||||||
|
<option value="{{ $p->id }}"
|
||||||
|
data-path="{{ is_string($p->path) ? $p->path : json_encode($p->path) }}"
|
||||||
|
{{ old('provinsi_id') == $p->id ? 'selected' : '' }}>{{ $p->nama }}
|
||||||
|
</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
@error('provinsi_id')<div class="error invalid-feedback">{{ $message }}</div>@enderror
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3 form-control-validation">
|
||||||
|
<label class="form-label">Kabupaten/Kota <span class="text-danger">*</span></label>
|
||||||
|
<select name="kabupatenkota_id" id="kabupatenkota_id" class="form-select @error('kabupaten_id') is-invalid @enderror" disabled required>
|
||||||
|
<option value="">Pilih Kabupaten/Kota</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
@error('kabupaten_id')<div class="error invalid-feedback">{{ $message }}</div>@enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3 form-control-validation">
|
||||||
|
<label class="form-label">Kecamatan <span class="text-danger">*</span></label>
|
||||||
|
<select name="kecamatan_id" id="kecamatan_id" class="form-select @error('kecamatan_id') is-invalid @enderror" disabled required>
|
||||||
|
<option value="">Pilih Kecamatan</option>
|
||||||
|
</select>
|
||||||
|
@error('kecamatan_id')<div class="error invalid-feedback">{{ $message }}</div>@enderror
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3 form-control-validation">
|
||||||
|
<label class="form-label">Desa/Kelurahan <span class="text-danger">*</span></label>
|
||||||
|
<select name="desa_kelurahan_id" id="desa_kelurahan_id" class="form-select @error('kecamatan_id') is-invalid @enderror" disabled required>
|
||||||
|
<option value="">Pilih Desa/Kelurahan</option>
|
||||||
|
</select>
|
||||||
|
@error('desa_kelurahan_id')<div class="error invalid-feedback">{{ $message }}</div>@enderror
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 mb-3 form-control-validation">
|
||||||
|
<label class="form-label">Raw Data Koordinat Lahan (Auto-generated JSON) <span class="text-danger">*</span></label>
|
||||||
|
<textarea name="path" id="path" class="form-control @error('path') is-invalid @enderror" rows="4" readonly placeholder="Koordinat akan terisi otomatis setelah Anda menggambar polygon di peta..."></textarea>
|
||||||
|
<small class="text-muted">Pastikan menggambar polygon di peta dengan menyambungkan titik akhir ke titik awal.</small>
|
||||||
|
@error('path')<div class="error invalid-feedback">{{ $message }}</div>@enderror
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-6 mb-4">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
|
<h6 class="text-primary mb-0"><i class="ti tabler-map me-1"></i> Gambar Area Lahan</h6>
|
||||||
|
<span class="badge bg-label-info">Gunakan tool ⬟ di kiri peta</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="map" class="border rounded shadow-sm"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col-12 text-end">
|
||||||
|
<button type="reset" class="btn btn-label-secondary me-2">Reset</button>
|
||||||
|
<button type="submit" class="btn btn-primary"><i class="ti tabler-device-floppy me-2"></i> Simpan Data</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12 col-lg-2 col-md-3">
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-lg-10 col-md-9">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover table-sm">
|
||||||
|
<thead class="border-top">
|
||||||
|
<tr>
|
||||||
|
<th>No</th>
|
||||||
|
<th>Nama</th>
|
||||||
|
<th>Komoditas</th>
|
||||||
|
<th>Jenis</th>
|
||||||
|
<th>Varietas</th>
|
||||||
|
<th>Aksi</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@forelse($lahanSelected->tanaman as $index => $item)
|
||||||
|
<tr>
|
||||||
|
<td>{{ $loop->iteration }}</td>
|
||||||
|
<td><span class="text-heading">{{ $item->nama }}</span></td>
|
||||||
|
<td><span class="text-muted">{{ $item->komoditas->nama }}</span></td>
|
||||||
|
<td><span class="text-muted">{{ $item->jenisKomoditas->nama }}</span></td>
|
||||||
|
<td><span class="text-muted">{{ $item->varietas->nama }} </span></td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<a href="{{ route('petani.edit', $item->id) }}" class="btn btn-icon btn-text-secondary rounded-pill edit-record"><i class="ti tabler-edit ti-md"></i></a>
|
||||||
|
<a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill delete-record" data-id="{{ $item->id }}" data-nama="{{ $item->nama }}"><i class="ti tabler-trash ti-md"></i></a>
|
||||||
|
<a href="{{ route('petani.show', $item->id) }}" class="btn btn-icon btn-text-secondary rounded-pill view-record"><i class="ti tabler-eye ti-md"></i></a>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@empty
|
||||||
|
<tr><td colspan="6" class="text-center py-4">Tidak ada data ditemukan.</td></tr>
|
||||||
|
@endforelse
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@push('scripts')
|
||||||
|
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict';
|
||||||
|
$(document).ready(function () {
|
||||||
|
|
||||||
|
$('#provinsi_id').select2().change(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var provinsiId = $(this).val();
|
||||||
|
focusToRegionBoundary(this);
|
||||||
|
|
||||||
|
$('#kabupatenkota_id').prop('disabled', !provinsiId).val('').trigger('change');
|
||||||
|
$('#kecamatan_id').prop('disabled', true).val('').trigger('change');
|
||||||
|
$('#desa_kelurahan_id').prop('disabled', true).val('').trigger('change');
|
||||||
|
|
||||||
|
if (provinsiId) {
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ route("kabupatenkota.byprovinsi", ":id") }}'.replace(':id', provinsiId),
|
||||||
|
method: 'GET',
|
||||||
|
success: function(data) {
|
||||||
|
$('#kabupatenkota_id').empty().append('<option value="">Pilih Kabupaten/Kota</option>');
|
||||||
|
data.forEach(function(kabupaten) {
|
||||||
|
let path = '';
|
||||||
|
if(kabupaten.path) {
|
||||||
|
path = typeof kabupaten.path === 'string' ? kabupaten.path : JSON.stringify(kabupaten.path);
|
||||||
|
}
|
||||||
|
$('#kabupatenkota_id').append('<option value="' + kabupaten.id + '" data-path="' + path + '">' + kabupaten.nama + '</option>');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#kabupatenkota_id').select2().change(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var kabupatenId = $(this).val();
|
||||||
|
focusToRegionBoundary(this);
|
||||||
|
$('#kecamatan_id').prop('disabled', !kabupatenId).val('').trigger('change');
|
||||||
|
$('#desa_kelurahan_id').prop('disabled', true).val('').trigger('change');
|
||||||
|
|
||||||
|
if (kabupatenId) {
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ route("kecamatan.bykabupatenkota", ":id") }}'.replace(':id', kabupatenId),
|
||||||
|
method: 'GET',
|
||||||
|
success: function(data) {
|
||||||
|
$('#kecamatan_id').empty().append('<option value="">Pilih Kecamatan</option>');
|
||||||
|
data.forEach(function(kecamatan) {
|
||||||
|
let path = '';
|
||||||
|
if(kecamatan.path) {
|
||||||
|
path = typeof kecamatan.path === 'string' ? kecamatan.path : JSON.stringify(kecamatan.path);
|
||||||
|
}
|
||||||
|
$('#kecamatan_id').append('<option value="' + kecamatan.id + '" data-path="' + path + '">' + kecamatan.nama + '</option>');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#kecamatan_id').select2().change(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var kecamatanId = $(this).val();
|
||||||
|
focusToRegionBoundary(this);
|
||||||
|
$('#desa_kelurahan_id').prop('disabled', !kecamatanId).val('').trigger('change');
|
||||||
|
|
||||||
|
if (kecamatanId) {
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ route("desakelurahan.bykecamatan", ":id") }}'.replace(':id', kecamatanId),
|
||||||
|
method: 'GET',
|
||||||
|
success: function(data) {
|
||||||
|
$('#desa_kelurahan_id').empty().append('<option value="">Pilih Desa/Kelurahan</option>');
|
||||||
|
data.forEach(function(desa) {
|
||||||
|
let path = '';
|
||||||
|
if(desa.path) {
|
||||||
|
path = typeof desa.path === 'string' ? desa.path : JSON.stringify(desa.path);
|
||||||
|
}
|
||||||
|
$('#desa_kelurahan_id').append('<option value="' + desa.id + '" data-path="' + path + '">' + desa.nama + '</option>');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#desa_kelurahan_id').select2().change(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
focusToRegionBoundary(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#komoditas_id').select2().change(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var komoditasId = $(this).val();
|
||||||
|
$('#jenis_komoditas_id').prop('disabled', !komoditasId).val('').trigger('change');
|
||||||
|
$('#varietas_id').prop('disabled', true).val('').trigger('change');
|
||||||
|
|
||||||
|
if (komoditasId) {
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ route("jenis-komoditas.by-komoditas", ":id") }}'.replace(':id', komoditasId),
|
||||||
|
method: 'GET',
|
||||||
|
success: function(data) {
|
||||||
|
$('#jenis_komoditas_id').empty().append('<option value="">Pilih Jenis Komoditas</option>');
|
||||||
|
data.data.forEach(function(jenis) {
|
||||||
|
$('#jenis_komoditas_id').append('<option value="' + jenis.id + '">' + jenis.nama + '</option>');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#jenis_komoditas_id').select2().change(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var jenisKomoditasId = $(this).val();
|
||||||
|
$('#varietas_id').prop('disabled', !jenisKomoditasId).val('').trigger('change');
|
||||||
|
|
||||||
|
if (jenisKomoditasId) {
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ route("varietas.by-jenis-komoditas", ":id") }}'.replace(':id', jenisKomoditasId),
|
||||||
|
method: 'GET',
|
||||||
|
success: function(data) {
|
||||||
|
$('#varietas_id').empty().append('<option value="">Pilih Varietas</option>');
|
||||||
|
data.data.forEach(function(jenis) {
|
||||||
|
$('#varietas_id').append('<option value="' + jenis.id + '">' + jenis.nama + '</option>');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#varietas_id').select2();
|
||||||
|
|
||||||
|
// MAP
|
||||||
|
let map = L.map('map').setView([-0.789275, 113.921327], 5); // Default: Tengah Indonesia
|
||||||
|
|
||||||
|
L.tileLayer('http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}', {
|
||||||
|
maxZoom: 22,
|
||||||
|
subdomains: ['mt0', 'mt1', 'mt2', 'mt3'],
|
||||||
|
attribution: '© Google Maps Satellite'
|
||||||
|
}).addTo(map);
|
||||||
|
|
||||||
|
let regionBoundaryLayer = L.featureGroup().addTo(map);
|
||||||
|
|
||||||
|
function focusToRegionBoundary(selectElement) {
|
||||||
|
regionBoundaryLayer.clearLayers(); // Bersihkan garis wilayah sebelumnya
|
||||||
|
|
||||||
|
let selectedOption = selectElement.options[selectElement.selectedIndex];
|
||||||
|
if (!selectedOption || !selectedOption.hasAttribute('data-path')) return;
|
||||||
|
|
||||||
|
let pathStr = selectedOption.getAttribute('data-path');
|
||||||
|
if (!pathStr || pathStr === "null" || pathStr === "") return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let rawData = typeof pathStr === 'string' ? JSON.parse(pathStr) : pathStr;
|
||||||
|
|
||||||
|
if (Array.isArray(rawData) && rawData.length > 0) {
|
||||||
|
|
||||||
|
function formatCoordinates(coords) {
|
||||||
|
if (coords.length === 2 && typeof coords[0] === 'number') {
|
||||||
|
return [coords[0], coords[1]]; // JANGAN DIBALIK
|
||||||
|
}
|
||||||
|
return coords.map(formatCoordinates);
|
||||||
|
}
|
||||||
|
|
||||||
|
let latLngs = formatCoordinates(rawData);
|
||||||
|
|
||||||
|
let polygon = L.polygon(latLngs, {
|
||||||
|
color: '#3b5998',
|
||||||
|
fillColor: '#3b5998',
|
||||||
|
fillOpacity: 0.1,
|
||||||
|
weight: 2,
|
||||||
|
dashArray: '5, 5',
|
||||||
|
interactive: false
|
||||||
|
});
|
||||||
|
|
||||||
|
regionBoundaryLayer.addLayer(polygon);
|
||||||
|
map.fitBounds(polygon.getBounds(), { padding: [20, 20] });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Format JSON path wilayah tidak valid:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let drawnItems = new L.FeatureGroup();
|
||||||
|
map.addLayer(drawnItems);
|
||||||
|
|
||||||
|
let drawControl = new L.Control.Draw({
|
||||||
|
draw: {
|
||||||
|
polygon: {
|
||||||
|
allowIntersection: false,
|
||||||
|
showArea: true,
|
||||||
|
shapeOptions: {
|
||||||
|
color: '#28c76f',
|
||||||
|
fillColor: '#28c76f',
|
||||||
|
fillOpacity: 0.4,
|
||||||
|
weight: 3
|
||||||
|
}
|
||||||
|
},
|
||||||
|
polyline: false,
|
||||||
|
circle: false,
|
||||||
|
rectangle: false,
|
||||||
|
marker: false,
|
||||||
|
circlemarker: false
|
||||||
|
},
|
||||||
|
edit: {
|
||||||
|
featureGroup: drawnItems,
|
||||||
|
remove: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
map.addControl(drawControl);
|
||||||
|
|
||||||
|
map.on(L.Draw.Event.CREATED, function (e) {
|
||||||
|
let layer = e.layer;
|
||||||
|
|
||||||
|
drawnItems.clearLayers();
|
||||||
|
drawnItems.addLayer(layer);
|
||||||
|
|
||||||
|
updatePathTextarea(layer);
|
||||||
|
});
|
||||||
|
|
||||||
|
map.on(L.Draw.Event.EDITED, function (e) {
|
||||||
|
e.layers.eachLayer(function (layer) {
|
||||||
|
updatePathTextarea(layer);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
map.on(L.Draw.Event.DELETED, function () {
|
||||||
|
document.getElementById('path').value = '';
|
||||||
|
});
|
||||||
|
|
||||||
|
function updatePathTextarea(layer) {
|
||||||
|
let latlngs = layer.getLatLngs()[0];
|
||||||
|
let pathData = latlngs.map(function(latlng) {
|
||||||
|
return [latlng.lng, latlng.lat];
|
||||||
|
});
|
||||||
|
document.getElementById('path').value = JSON.stringify(pathData);
|
||||||
|
|
||||||
|
let area = L.GeometryUtil.geodesicArea(latlngs);
|
||||||
|
|
||||||
|
console.log(area);
|
||||||
|
|
||||||
|
$('#luas_lahan').val(area.toFixed(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// FORM
|
||||||
|
|
||||||
|
$('#petani-lahan-tanaman').validate({
|
||||||
|
rules: {
|
||||||
|
luas_lahan: { required: true },
|
||||||
|
komoditas_id: { required: true },
|
||||||
|
jenis_komoditas_id: { required: true },
|
||||||
|
varietas_id: { required: true },
|
||||||
|
desa_kelurahan_id: { required: true },
|
||||||
|
jumlah_tanaman: { required: true },
|
||||||
|
},
|
||||||
|
messages: {
|
||||||
|
luas_lahan: { required: "Luas lahan wajib diisi" },
|
||||||
|
komoditas_id: { required: "Komoditas wajib diisi" },
|
||||||
|
jenis_komoditas_id: { required: "Jenis komoditas wajib diisi" },
|
||||||
|
varietas_id: { required: "Varietas wajib diisi" },
|
||||||
|
desa_kelurahan_id: { required: "Desa/Kelurahan wajib diisi" },
|
||||||
|
jumlah_tanaman: { required: "Jumlah tanaman wajib diisi" },
|
||||||
|
},
|
||||||
|
errorElement: 'div',
|
||||||
|
errorPlacement: function (error, element) {
|
||||||
|
error.addClass('invalid-feedback');
|
||||||
|
element.closest('.mb-6, .form-control-validation').append(error);
|
||||||
|
},
|
||||||
|
highlight: function (element) {
|
||||||
|
$(element).addClass('is-invalid');
|
||||||
|
},
|
||||||
|
unhighlight: function (element) {
|
||||||
|
$(element).removeClass('is-invalid');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<ul class="nav nav-align-left nav-pills flex-column">
|
<ul class="nav nav-align-left nav-pills flex-column">
|
||||||
@foreach($lahan as $item)
|
@foreach($lahan as $item)
|
||||||
<li class="nav-item mb-1">
|
<li class="nav-item mb-1">
|
||||||
<a class="nav-link {{ $loop->first ? 'active' : '' }}" href="{{ route('petani.lahan-tanaman.edit', ['petani' => $petani->id, 'id' => $item->id]) }}">
|
<a class="nav-link {{ $loop->first ? 'active' : '' }}" href="{{ route('petani.lahan-tanaman.edit', ['petani' => $petani->id, 'lahan_tanaman' => $item->id]) }}">
|
||||||
<span class="align-middle">
|
<span class="align-middle">
|
||||||
<i class="icon-base ti tabler-building-store icon-sm me-1_5"></i>{{ $item->nama }}
|
<i class="icon-base ti tabler-building-store icon-sm me-1_5"></i>{{ $item->nama }}
|
||||||
</span>
|
</span>
|
||||||
@@ -45,7 +45,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@if($lahan->count() > 0)
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user