diff --git a/app/Enums/KeparahanSerangan.php b/app/Enums/KeparahanSerangan.php index f6ad0b2..a030eb9 100644 --- a/app/Enums/KeparahanSerangan.php +++ b/app/Enums/KeparahanSerangan.php @@ -7,4 +7,21 @@ enum KeparahanSerangan: string case RINGAN = 'ringan'; case SEDANG = 'sedang'; case BERAT = 'berat'; + + public function label(): string + { + return match($this) { + self::RINGAN => 'Ringan', + self::SEDANG => 'Sedang', + self::BERAT => 'Berat', + }; + } + + public static function options(): array + { + return collect(self::cases())->map(fn ($case) => [ + 'value' => $case->value, + 'label' => $case->label(), + ])->toArray(); + } } \ No newline at end of file diff --git a/app/Enums/KondisiTanaman.php b/app/Enums/KondisiTanaman.php index 00c44e3..ae73179 100644 --- a/app/Enums/KondisiTanaman.php +++ b/app/Enums/KondisiTanaman.php @@ -7,6 +7,24 @@ enum KondisiTanaman: string case BAIK = 'baik'; case SEDANG = 'sedang'; case BURUK = 'buruk'; - case SAKIT= 'sakit'; + //case SAKIT= 'sakit'; case MATI = 'mati'; + + public function label(): string + { + return match($this) { + self::BAIK => 'Baik', + self::SEDANG => 'Sedang', + self::BURUK => 'Buruk', + self::MATI => 'Mati', + }; + } + + public static function options(): array + { + return collect(self::cases())->map(fn ($case) => [ + 'value' => $case->value, + 'label' => $case->label(), + ])->toArray(); + } } diff --git a/app/Http/Controllers/Web/Produktivitas/PetaniController.php b/app/Http/Controllers/Web/Produktivitas/PetaniController.php index 70109f3..d3c85fb 100644 --- a/app/Http/Controllers/Web/Produktivitas/PetaniController.php +++ b/app/Http/Controllers/Web/Produktivitas/PetaniController.php @@ -100,8 +100,9 @@ class PetaniController extends Controller $validatedData['foto'] = $file_foto->store('petani/foto'); } - Petani::create([...$validatedData, - 'uid' => 'PTN-'. strtoupper(Str::random(10)), + $petaniUID = strtoupper(Str::random(10)); + $petani = Petani::create([...$validatedData, + 'uid' => 'PTN-'. $petaniUID, 'created_by' => auth()->id(), 'updated_by' => auth()->id()]); diff --git a/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php b/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php index 1cfa8b5..1932d86 100644 --- a/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php +++ b/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php @@ -94,6 +94,10 @@ class PetaniLahanController extends Controller 'serangan_hama' => ['nullable', 'string', new Enum(SeranganHama::class)], 'penyakit_tanaman' => ['nullable', 'string', new Enum(PenyakitTanaman::class)], 'keparahan_serangan' => ['nullable', 'string', new Enum(KeparahanSerangan::class)], + 'komoditas_lain' => ['nullable', 'array'], + 'komoditas_lain.*' => ['integer', 'exists:master_komoditas,id'], + 'tanaman_penaung' => ['nullable', 'array'], + 'tanaman_penaung.*' => ['integer', 'exists:master_komoditas,id'], ]); $komoditas = Komoditas::where('id', $request->komoditas_id)->first(); @@ -167,6 +171,7 @@ class PetaniLahanController extends Controller $lahan = Lahan::where('petani_id', $petaniId) ->orderBy('id', 'asc') ->get(); + $lahanSelected = Lahan::where('petani_id', $petaniId)->findOrFail($id); @@ -206,6 +211,10 @@ class PetaniLahanController extends Controller 'serangan_hama' => ['nullable', 'string', new Enum(SeranganHama::class)], 'penyakit_tanaman' => ['nullable', 'string', new Enum(PenyakitTanaman::class)], 'keparahan_serangan' => ['nullable', 'string', new Enum(KeparahanSerangan::class)], + 'komoditas_lain' => ['nullable', 'array'], + 'komoditas_lain.*' => ['integer', 'exists:master_komoditas,id'], + 'tanaman_penaung' => ['nullable', 'array'], + 'tanaman_penaung.*' => ['integer', 'exists:master_komoditas,id'], ]); $komoditas = Komoditas::where('id', $request->komoditas_id)->first(); diff --git a/app/Models/Pertanian/AksesPasar.php b/app/Models/Pertanian/AksesPasar.php index eedc554..674b65d 100644 --- a/app/Models/Pertanian/AksesPasar.php +++ b/app/Models/Pertanian/AksesPasar.php @@ -4,8 +4,10 @@ namespace App\Models\Pertanian; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Str; use App\Models\User; use App\Models\Pertanian\Petani; +use App\Models\Pertanian\SkorPetani; class AksesPasar extends Model { @@ -38,6 +40,30 @@ class AksesPasar extends Model protected $casts = [ 'saluran_terdahulu' => 'array', ]; + + protected static function booted(): void + { + static::saved(function (AksesPasar $aksesPasar) { + + $petani = Petani::find($aksesPasar->petani_id); + $skor = SkorPetani::where('petani_id')->orderBy('id')->first(); + if (!$skor) { + $petaniUid = $petani->uid; + $part = explode('-', $petaniUid); + $skor = SkorPetani::create([ + 'petani_id' => $petani->id, + 'uid' => 'SKR-' . $part[1] . '-' . strtoupper(Str::random(10)), + 'created_by' => $petani->created_by, + 'updated_by' => $petani->updated_by + ]); + } + $skor->update([ + 'skor_d6_k1_6_pengalaman_menjual_ke_saluran_berbeda' => $aksesPasar->skor_pengalaman, + 'skor_d6_k4_1_kesadaran_akses_pasar_premium' => $aksesPasar->skor_kesadaran_premium, + 'skor_d6_k5_1_hambatan_mutu' => $aksesPasar->skor_kepercayaan_responden + ]); + }); + } public function petani() diff --git a/app/Models/Pertanian/Lahan.php b/app/Models/Pertanian/Lahan.php index c4ce730..c876134 100644 --- a/app/Models/Pertanian/Lahan.php +++ b/app/Models/Pertanian/Lahan.php @@ -14,6 +14,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use App\Models\Pertanian\Komoditas; use App\Models\Master\JenisKomoditas; use App\Models\Master\Varietas; +use App\Enums\KondisiTanaman; class Lahan extends Model { @@ -48,11 +49,17 @@ class Lahan extends Model 'created_by', 'updated_by', 'deleted_by', + + 'komoditas_lain', + 'tanaman_penaung', ]; protected $casts = [ 'status_kepemilikan' => StatusLahan::class, 'path' => 'array', + 'komoditas_lain' => 'array', + 'tanaman_penaung' => 'array', + 'kondisi_tanaman' => KondisiTanaman::class, ]; public function profile(): BelongsTo diff --git a/app/Models/Pertanian/Petani.php b/app/Models/Pertanian/Petani.php index 7c9f3ae..2efbda8 100644 --- a/app/Models/Pertanian/Petani.php +++ b/app/Models/Pertanian/Petani.php @@ -15,6 +15,8 @@ use App\Models\Wilayah\DesaKelurahan; use App\Enums\Pendidikan; use App\Enums\Pernikahan; +use App\Models\Pertanian\SkorPetani; + class Petani extends Model { use SoftDeletes; @@ -78,6 +80,28 @@ class Petani extends Model return $this->belongsTo(User::class, 'user_id'); } + protected static function booted(): void + { + static::saved(function (Petani $petani) { + + $skor = SkorPetani::where('petani_id')->orderBy('id')->first(); + if (!$skor) { + $petaniUid = $petani->uid; + $part = explode('-', $petaniUid); + $skor = SkorPetani::create([ + 'uid' => 'SKR-' . $part[1] . '-' . strtoupper(Str::random(10)), + 'created_by' => $petani->created_by, + 'updated_by' => $petani->updated_by + ]); + } + }); + } + + public function skor(): HasOne + { + return $this->hasOne(SkorPetani::class, 'petani_id'); + } + public function praktikBudidaya(): HasOne { return $this->hasOne(PraktikBudidaya::class, 'petani_id')->latestOfMany(); diff --git a/app/Models/Pertanian/PraktikBudidaya.php b/app/Models/Pertanian/PraktikBudidaya.php index 5ba2ea7..9f82177 100644 --- a/app/Models/Pertanian/PraktikBudidaya.php +++ b/app/Models/Pertanian/PraktikBudidaya.php @@ -5,9 +5,13 @@ namespace App\Models\Pertanian; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Factories\HasFactory; -use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Support\Str; use App\Models\Pertanian\Petani; +use App\Models\Pertanian\SkorPetani; class PraktikBudidaya extends Model { @@ -71,6 +75,36 @@ class PraktikBudidaya extends Model 'deleted_by', ]; + protected static function booted(): void + { + static::saved(function (PraktikBudidaya $praktikBudidaya) { + + $petani = Petani::find($praktikBudidaya->petani_id); + $skor = SkorPetani::where('petani_id', $petani->id)->orderBy('id')->first(); + if (!$skor) { + $petaniUid = $petani->uid; + $part = explode('-', $petaniUid); + $skor = SkorPetani::create([ + 'petani_id' => $petani->id, + 'uid' => 'SKR-' . $part[1] . '-' . strtoupper(Str::random(10)), + 'created_by' => $petani->created_by, + 'updated_by' => $petani->updated_by + ]); + } + $skor->update([ + + 'skor_d2_k2_3_praktik_pemangkasan' => $praktikBudidaya->frekuensi_pemangkasan_komoditas_utama, + 'skor_d2_k2_4_praktik_pemupukan' => $praktikBudidaya->pemberian_pupuk, + 'skor_d2_k2_5_pengendalian_opt' => $praktikBudidaya->metode_penanganan_hama_penyakit, + 'skor_d2_k2_6_sanitasi_kebun' => $praktikBudidaya->frekuensi_sanitasi_lahan, + 'skor_d2_k2_6b_pengelolaan_gulma' => $praktikBudidaya->penanganan_gulma, + 'skor_d2_k2_7_penglolaan_air_irigasi' => $praktikBudidaya->kondisi_pengelolaan_air_irigasi, + //'skor_d2_k2_8_praktik_konservasi_tanah' => $praktikBudidaya->kebiasaan_konservasi_tanah, + //'skor_d2_k3_1_penentuan_pematangan' => $praktikBudidaya-> + ]); + }); + } + public function petani(): BelongsTo { return $this->belongsTo(Petani::class, 'petani_id'); diff --git a/app/Models/Pertanian/SkorPetani.php b/app/Models/Pertanian/SkorPetani.php new file mode 100644 index 0000000..de03e79 --- /dev/null +++ b/app/Models/Pertanian/SkorPetani.php @@ -0,0 +1,66 @@ + MinatPembeliHargaStabil::class, ]; + protected static function booted(): void + { + static::saved(function (SosialEkonomi $sosialEkonomi) { + + $petani = Petani::find($sosialEkonomi->petani_id); + $skor = SkorPetani::where('petani_id', $petani->id)->orderBy('id')->first(); + if (!$skor) { + $petaniUid = $petani->uid; + $part = explode('-', $petaniUid); + $skor = SkorPetani::create([ + 'petani_id' => $petani->id, + 'uid' => 'SKR-' . $part[1] . '-' . strtoupper(Str::random(10)), + 'created_by' => $petani->created_by, + 'updated_by' => $petani->updated_by + ]); + } + $skor->update([ + 'skor_d4_k5_1_kepemilikan_rekening' => $sosialEkonomi->status_rekening_tabungan, + 'skor_d4_k5_2_pengalaman_kredit_formal' => $sosialEkonomi->pengalaman_kredit_kebun, + 'skor_d4_k5_3_kepemilikan_aset_produktif' => $sosialEkonomi->kondisi_aset_produktif, + 'skor_d4_k5_4_akses_program_bantuan' => $sosialEkonomi->keterlibatan_program_keuangan_formal, + + 'skor_d4_k6_3_keberadaan_hutang_terkait_panen' => $sosialEkonomi->keterikatan_hutang_panen, + 'skor_d4_k6_5a_praktik_ijon' => $sosialEkonomi->praktik_ijon, + 'skor_d4_k6_5b_kebebasan_memilih_pembeli' => $sosialEkonomi->kebebasan_memilih_pembeli, + ]); + }); + } + public function petani(): BelongsTo { return $this->belongsTo(Petani::class, 'petani_id'); diff --git a/database/migrations/2026_07_07_135320_create_petani_skor_table.php b/database/migrations/2026_07_07_135320_create_petani_skor_table.php new file mode 100644 index 0000000..8b7d7f8 --- /dev/null +++ b/database/migrations/2026_07_07_135320_create_petani_skor_table.php @@ -0,0 +1,91 @@ +id(); + $table->string('uid')->nullable()->unique(); + + $table->foreignId('petani_id')->nullable()->constrained('petani')->onDelete('cascade'); + + $table->float('skor_kesiapan_adopsi', 10)->nullable(); + + $table->float('skor_d2_sistem_praktik_budidaya', 10)->nullable(); + $table->float('skor_d4_sosial_ekonomi', 10)->nullable(); + $table->float('skor_d6_rantai_nilai_akses_pasar', 10)->nullable(); + + $table->float('skor_komp_1_d4_k3_motivasi_kapasitas_adopsi', 10)->nullable(); + $table->float('skor_komp_2_d4_k2_ekonomi_rumah_tangga', 10)->nullable(); + $table->float('skor_komp_3_d2_praktik_budidaya_gap', 10)->nullable(); + $table->float('skor_komp_4_d4_k4_keterlibatan_kelembagaan', 10)->nullable(); + $table->float('skor_komp_5_d4_k5_k6_akses_kebebasan_keuangan', 10)->nullable(); + $table->float('skor_komp_6_d6_k1_k4_k5_rantai_nilai_akses_pasar', 10)->nullable(); + + $table->float('skor_d4_k3_1_praktik_baru', 10)->nullable(); + $table->float('skor_d4_k3_4_pemahaman_mutu_harga', 10)->nullable(); + $table->float('skor_d4_k3_5_role_model', 10)->nullable(); + $table->float('skor_d4_k3_6_kemampuan_keterlibatan_program', 10)->nullable(); + $table->float('skor_d4_k3_7_orientasi_jangka_panjang', 10)->nullable(); + + $table->float('skor_d4_k2_5_stabilitas_penghasilan', 10)->nullable(); + $table->float('skor_d4_k2_8_kemampuan_menabung', 10)->nullable(); + $table->float('skor_d4_k2_9_kecukupan_penghasilan', 10)->nullable(); + $table->float('skor_d4_k2_3_k2_7_rasio_biaya_produksi_pendapatan', 10)->nullable(); + $table->float('skor_d4_k2_11_hak_kelola_lahan', 10)->nullable(); + + $table->float('skor_d2_k2_3_praktik_pemangkasan', 10)->nullable(); + $table->float('skor_d2_k2_4_praktik_pemupukan', 10)->nullable(); + $table->float('skor_d2_k2_5_pengendalian_opt', 10)->nullable(); + $table->float('skor_d2_k2_6_sanitasi_kebun', 10)->nullable(); + $table->float('skor_d2_k2_6b_pengelolaan_gulma', 10)->nullable(); + $table->float('skor_d2_k2_7_penglolaan_air_irigasi', 10)->nullable(); + $table->float('skor_d2_k2_8_praktik_konservasi_tanah', 10)->nullable(); + $table->float('skor_d2_k3_1_penentuan_pematangan', 10)->nullable(); + $table->float('skor_d2_k3_5_sortasi_awal_pemisahan_kualitas', 10)->nullable(); + + $table->float('skor_d4_k4_2_keaktifan_pertemuan', 10)->nullable(); + $table->float('skor_d4_k4_3_peran_dalam_kelompok', 10)->nullable(); + $table->float('skor_d4_k4_4_manfaat_dirasakan', 10)->nullable(); + + $table->float('skor_d4_k5_1_kepemilikan_rekening', 10)->nullable(); + $table->float('skor_d4_k5_2_pengalaman_kredit_formal', 10)->nullable(); + $table->float('skor_d4_k5_3_kepemilikan_aset_produktif', 10)->nullable(); + //$table->float('skor_d4_k5_4_kepemilikan_aset_tidak_produktif', 10)->nullable(); + //$table->float('skor_d4_k5_4_akses_program_bantuan_formal', 10)->nullable(); + $table->float('skor_d4_k5_4_akses_program_bantuan', 10)->nullable(); + + $table->float('skor_d4_k6_3_keberadaan_hutang_terkait_panen', 10)->nullable(); + $table->float('skor_d4_k6_5a_praktik_ijon', 10)->nullable(); + $table->float('skor_d4_k6_5b_kebebasan_memilih_pembeli', 10)->nullable(); + + $table->float('skor_d6_k1_6_pengalaman_menjual_ke_saluran_berbeda', 10)->nullable(); + $table->float('skor_d6_k4_1_kesadaran_akses_pasar_premium', 10)->nullable(); + $table->float('skor_d6_k5_1_hambatan_mutu', 10)->nullable(); + + $table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null'); + $table->foreignId('updated_by')->nullable()->constrained('users')->onDelete('set null'); + $table->foreignId('deleted_by')->nullable()->constrained('users')->onDelete('set null'); + + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('petani_skor'); + } +}; diff --git a/database/migrations/2026_07_07_135321_update_petani_master_dan_lahan_table.php b/database/migrations/2026_07_07_135321_update_petani_master_dan_lahan_table.php new file mode 100644 index 0000000..faf26fa --- /dev/null +++ b/database/migrations/2026_07_07_135321_update_petani_master_dan_lahan_table.php @@ -0,0 +1,26 @@ +json('komoditas_lain')->nullable(); + $table->json('tanaman_penaung')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + } +}; diff --git a/resources/views/produktivitas/petani/lahan/add.blade.php b/resources/views/produktivitas/petani/lahan/add.blade.php index 558b84b..dd859a2 100644 --- a/resources/views/produktivitas/petani/lahan/add.blade.php +++ b/resources/views/produktivitas/petani/lahan/add.blade.php @@ -32,7 +32,7 @@
- @include('produktivitas.petani.header', ['petani' => $petani]) + @include('produktivitas.petani.header')
@@ -135,6 +135,28 @@ @error('keparahan_serangan')
{{ $message }}
@enderror
+
+
+ + + @error('komoditas_lain')
{{ $message }}
@enderror +
+
+ + + @error('tanaman_penaung[]')
{{ $message }}
@enderror +
+
@@ -229,6 +251,8 @@ $('#serangan_hama').select2(); $('#penyakit_tanaman').select2(); $('#keparahan_serangan').select2(); + $('#komoditas_lain').select2(); + $('#tanaman_penaung').select2(); $('#provinsi_id').select2().change(function(e) { e.preventDefault(); diff --git a/resources/views/produktivitas/petani/lahan/edit.blade.php b/resources/views/produktivitas/petani/lahan/edit.blade.php index b7a81c5..8c9416a 100644 --- a/resources/views/produktivitas/petani/lahan/edit.blade.php +++ b/resources/views/produktivitas/petani/lahan/edit.blade.php @@ -46,7 +46,7 @@
-
Data Lahan dan Komoditas
+
Data Lahan dan Tanaman
@@ -147,7 +147,34 @@ @error('keparahan_serangan')
{{ $message }}
@enderror
- +
+
+ + + @error('komoditas_lain')
{{ $message }}
@enderror +
+
+ + + @error('tanaman_penaung[]')
{{ $message }}
@enderror +
+
@@ -320,6 +347,8 @@
+ + @include('produktivitas.petani.lahan.tanaman.edit') @include('produktivitas.petani.lahan.tanaman.delete') @@ -342,6 +371,13 @@ const selectedJenisKomoditas = "{{ optional($lahanSelected->jenisKomoditas)->id }}"; const selectedVarietas = "{{ optional($lahanSelected->varietas)->id }}"; + $('#kondisi_tanaman').select2(); + $('#serangan_hama').select2(); + $('#penyakit_tanaman').select2(); + $('#keparahan_serangan').select2(); + $('#komoditas_lain').select2(); + $('#tanaman_penaung').select2(); + $('#table-tanaman').DataTable({ "paging": true, "lengthChange": true, diff --git a/resources/views/produktivitas/petani/lahan/tanaman/delete.blade.php b/resources/views/produktivitas/petani/lahan/tanaman/delete.blade.php index a7d16e1..c6d9c2f 100644 --- a/resources/views/produktivitas/petani/lahan/tanaman/delete.blade.php +++ b/resources/views/produktivitas/petani/lahan/tanaman/delete.blade.php @@ -2,94 +2,70 @@