diff --git a/database/migrations/2026_09_17_134117_create_riwayat_petani_table.php b/database/migrations/2026_09_17_134117_create_riwayat_petani_table.php new file mode 100644 index 0000000..21c21b9 --- /dev/null +++ b/database/migrations/2026_09_17_134117_create_riwayat_petani_table.php @@ -0,0 +1,479 @@ +id(); + $table->string('periode_pencatatan')->comment('Penanda waktu snapshot, misal: Q1 2026'); + $table->string('uid')->nullable(); + + $table->foreignId('petani_id')->constrained('petani')->onDelete('cascade'); + + $table->string('nama'); + $table->boolean('jenis_kelamin'); + $table->string('tempat_lahir')->nullable(); + $table->date('tanggal_lahir'); + $table->string('pendidikan_terakhir')->nullable(); + + $table->string('alamat')->nullable(); + $table->foreignId('desa_kelurahan_id')->nullable()->constrained('master_desa_kelurahan'); + $table->string('nomor_telepon')->nullable(); + $table->string('foto', 500)->nullable(); + $table->string('status_perkawinan')->nullable(); + + $table->string('kk')->nullable(); + $table->string('ktp')->nullable(); + $table->string('path_kk', 500)->nullable(); + $table->string('file_kk')->nullable(); + $table->string('path_ktp', 500)->nullable(); + $table->string('file_ktp')->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(); + }); + + Schema::create('riwayat_map_lahan', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan')->comment('Penanda waktu snapshot, misal: Q1 2026'); + $table->string('uid')->nullable(); + $table->string('nama'); + $table->string('status_kepemilikan'); + + $table->foreignId('profile_id')->constrained('profiles'); + $table->foreignId('keluarga_pengelola_id')->nullable()->constrained('keluarga')->onDelete('set null'); + $table->foreignId('adat_pemilik_id')->nullable()->constrained('adat')->onDelete('set null'); + $table->foreignId('desa_kelurahan_id')->nullable()->constrained('master_desa_kelurahan'); + + $table->string('lat')->nullable(); + $table->string('long')->nullable(); + $table->jsonb('path')->nullable(); + $table->boolean('sertifikat')->default(false); + $table->boolean('konflik')->default(false); + $table->text('deskripsi')->nullable(); + $table->float('luas_lahan', 8)->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(); + }); + + Schema::create('riwayat_sertifikat_lahan', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); + $table->string('nomor_sertifikat'); + $table->date('tanggal_terbit'); + $table->date('tanggal_kadaluarsa')->nullable(); + $table->string('lembaga_penerbit')->nullable(); + + $table->foreignId('lahan_id')->constrained('map_lahan')->onDelete('cascade'); + + $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(); + }); + + Schema::create('riwayat_map_tanaman', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); + $table->string('nama'); + + $table->foreignId('komoditas_id')->constrained('master_komoditas')->onDelete('set null'); + $table->foreignId('jenis_komoditas_id')->constrained('jenis_komoditas')->onDelete('set null'); + $table->foreignId('varietas_id')->constrained('master_varietas')->onDelete('set null'); + $table->foreignId('profile_id')->constrained('profiles')->onDelete('set null'); + $table->foreignId('lahan_id')->constrained('map_lahan')->onDelete('set null'); + + $table->float('latitude')->nullable(); + $table->float('longitude')->nullable(); + $table->string('kondisi_tanaman')->nullable(); + $table->string('metode_pengumpulan')->nullable(); + $table->text('deskripsi')->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(); + }); + + Schema::create('riwayat_praktik_budidaya', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); + $table->foreignID('petani_id')->constrained('petani')->onDelete('cascade'); + + $table->string('tenaga_kerja')->nullable(); + $table->integer('frekuensi_pemangkasan_utama')->nullable(); + $table->jsonb('teknik_pemangkasan')->nullable(); + $table->string('frekuensi_pemangkasan_penaung')->nullable(); + $table->string('penyerbukan_manual')->nullable(); + $table->string('deskripsi_penyerbukan_manual')->nullable(); + $table->string('tingkat_keberhasilan_penyerbukan')->nullable(); + + $table->integer('pemberian_pupuk')->nullable(); + $table->string('jenis_pupuk')->nullable(); + $table->string('frekuensi_pemberian_pupuk')->nullable(); + $table->decimal('estimasi_dosis_pupuk_organik', 10, 2)->nullable(); + $table->decimal('estimasi_dosis_pupuk_anorganik', 10, 2)->nullable(); + $table->string('waktu_pemberian_pupuk')->nullable(); + $table->string('cara_pemberian_pupuk')->nullable(); + + $table->integer('metode_penanganan_opt')->nullable(); + $table->jsonb('jenis_hama')->nullable(); + $table->jsonb('jenis_penyakit')->nullable(); + $table->string('intensitas_serangan')->nullable(); + $table->string('waktu_kemunculan_terparah')->nullable(); + $table->string('metode_paling_sering_dilakukan')->nullable(); + $table->decimal('volume_obat_obatan_padat_permusim', 10, 2)->nullable(); + $table->decimal('volume_obat_obatan_cair_permusim', 10, 2)->nullable(); + + $table->integer('frekuensi_sanitasi_lahan')->nullable(); + $table->string('penanganan_sisa_buah_ranting')->nullable(); + $table->integer('penanganan_gulma')->nullable(); + + $table->integer('kondisi_pengelolaan_air')->nullable(); + $table->jsonb('sumber_air')->nullable(); + $table->string('sistem_irigasi')->nullable(); + $table->string('kebutuhan_air_permusim')->nullable(); + + $table->jsonb('kebiasaan_konservasi_tanah')->nullable(); + $table->string('pemahaman_manfaat_konservasi_tanah')->nullable(); + $table->integer('nilai_konservasi_tanah')->nullable(); + + $table->decimal('upah_tenaga_kerja', 13, 2)->nullable(); + $table->decimal('biaya_bibit', 13, 2)->nullable(); + $table->decimal('biaya_pupuk', 13, 2)->nullable(); + $table->decimal('biaya_obat_obatan', 13, 2)->nullable(); + $table->decimal('biaya_sewa_alat_produksi', 13, 2)->nullable(); + $table->decimal('biaya_penyediaan_air', 13, 2)->nullable(); + $table->decimal('biaya_produksi_lainnya', 13, 2)->nullable(); + $table->decimal('total_estimasi_biaya_produksi', 13, 2)->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(); + }); + + Schema::create('riwayat_survey_panen', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); + $table->foreignId('petani_id')->nullable()->constrained('petani')->onDelete('set null'); + + $table->integer('dasar_penentuan_panen')->nullable(); + $table->integer('frekuensi_panen_pertahun')->nullable(); + $table->string('bulan_panen_utama')->nullable(); + + $table->decimal('hasil_komoditas_utama_permusim', 10, 2)->nullable(); + $table->decimal('hasil_komoditas_lainnya_permusim', 10, 2)->nullable(); + $table->boolean('disimpan_untuk_sendiri')->nullable(); + $table->decimal('hasil_panen_disimpan', 10, 2)->nullable(); + $table->string('tujuan_disimpan')->nullable(); + + $table->integer('praktik_sortasi')->nullable(); + $table->string('bentuk_sortasi')->nullable(); + + $table->integer('hasil_panen_reject')->nullable(); + $table->string('jumlah_panen_reject')->nullable(); + $table->string('tindakan_panen_reject')->nullable(); + + $table->decimal('upah_tenaga_panen', 13, 2)->nullable(); + $table->decimal('biaya_pengangkutan_panen', 13, 2)->nullable(); + $table->decimal('biaya_wadah_Panen', 13, 2)->nullable(); + $table->decimal('biaya_sewa_alat_panen', 13, 2)->nullable(); + $table->decimal('biaya_panen_lainnya', 13, 2)->nullable(); + $table->decimal('total_estimasi_biaya_panen', 13, 2)->nullable(); + + $table->string('estimasi_kehilangan_akibat_opt')->nullable(); + $table->string('estimasi_kehilangan_akibat_hama_penyakit')->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(); + }); + + Schema::create('riwayat_survey_produktivitas', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); + $table->foreignId('petani_id')->nullable()->constrained('petani')->onDelete('set null'); + $table->foreignId('komoditas_id')->nullable()->constrained('master_komoditas')->onDelete('set null'); + + $table->decimal('kuantitas')->nullable(); + $table->string('satuan')->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(); + }); + + Schema::create('riwayat_sosial_ekonomi', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); + $table->foreignId('petani_id')->nullable()->constrained('petani')->onDelete('cascade'); + + $table->integer('jumlah_tanggungan')->nullable(); + $table->integer('anak_masih_sekolah')->nullable(); + $table->integer('yang_ikut_bekerja')->nullable(); + + $table->tinyInteger('skor_periode_paceklik')->nullable(); + $table->string('bulan_paceklik')->nullable(); + $table->text('sumber_penghasilan_paceklik')->nullable(); + + $table->unsignedBigInteger('total_estimasi_biaya_kebun_per_musim')->nullable(); + $table->tinyInteger('skor_kemampuan_menabung')->nullable(); + $table->unsignedBigInteger('estimasi_tabungan_per_bulan')->nullable(); + + $table->tinyInteger('skor_kecukupan_penghasilan')->nullable(); + $table->text('alasan_kecukupan_penghasilan')->nullable(); + + $table->string('status_kepemilikan_lahan')->nullable(); + $table->tinyInteger('skor_kejelasan_status_lahan')->nullable(); + $table->boolean('ada_sertifikat_dokumen')->nullable(); + $table->boolean('ada_sengketa')->nullable(); + $table->text('keterangan_sengketa')->nullable(); + $table->string('pihak_membantu_konflik')->nullable(); + $table->string('pihak_membantu_konflik_nama')->nullable(); + $table->year('tahun_bantuan_konflik')->nullable(); + $table->string('status_konflik')->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(); + }); + + Schema::create('riwayat_pendapatan_komoditas', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); + + $table->foreignId('sosial_ekonomi_id')->constrained('sosial_ekonomi')->onDelete('cascade'); + + $table->string('kategori')->comment('utama / lainnya'); + $table->string('komoditas')->nullable(); + $table->unsignedBigInteger('pendapatan')->nullable(); + $table->string('periode')->nullable()->comment('musim / tahun'); + + $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(); + }); + + Schema::create('riwayat_pendapatan_luar_pertanian', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); + $table->foreignId('sosial_ekonomi_id')->constrained('sosial_ekonomi')->onDelete('cascade'); + + $table->string('jenis_pekerjaan')->nullable(); + $table->unsignedBigInteger('estimasi_per_bulan')->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(); + }); + + Schema::create('riwayat_akses_pasar', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); + $table->foreignId('petani_id')->nullable()->constrained('petani')->onDelete('cascade'); + + $table->tinyInteger('skor_pengalaman')->nullable(); + $table->json('saluran_terdahulu')->nullable(); + $table->string('saluran_terdahulu_lainnya')->nullable(); + $table->string('alasan_berhenti')->nullable(); + + $table->string('praktik_fermentasi')->nullable(); + $table->text('proses_fermentasi')->nullable(); + $table->string('model_fermentasi_memungkinkan')->nullable(); + + $table->tinyInteger('skor_kesadaran_premium')->nullable(); + $table->string('sumber_info_premium')->nullable(); + + $table->time('waktu_mulai_wawancara')->nullable(); + $table->time('waktu_selesai_wawancara')->nullable(); + + $table->tinyInteger('skor_kepercayaan_responden')->nullable(); + $table->string('kehadiran_orang_lain')->nullable(); + $table->tinyInteger('skor_pengaruh_orang_lain')->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(); + }); + + Schema::create('riwayat_harga_jual_panen', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); + $table->foreignId('petani_id')->constrained('petani')->onDelete('cascade'); + + $table->string('bentuk_produk'); + $table->integer('harga_panen_terakhir')->nullable(); + $table->integer('harga_tahun_lalu')->nullable(); + $table->integer('harga_dua_tahun_lalu')->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(); + }); + + Schema::create('riwayat_survey_pelatihan', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); + $table->foreignId('petani_id')->nullable()->constrained('petani')->onDelete('set null'); + + $table->string('jenis_pelatihan'); + $table->string('penyelenggara'); + $table->integer('tahun_pelaksanaan'); + + $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(); + }); + + Schema::create('riwayat_survey_sertifikasi', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); + $table->foreignId('petani_id')->nullable()->constrained('petani')->onDelete('set null'); + + $table->string('jenis_sertifikasi'); + $table->string('lembaga_penerbit'); + $table->integer('tahun_pelaksanaan'); + $table->boolean('is_aktif')->default(false); + + $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(); + }); + + Schema::create('riwayat_petani_skor', function (Blueprint $table) { + $table->id(); + $table->string('periode_pencatatan'); + $table->string('uid')->nullable(); // Unique dihilangkan + + $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_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('riwayat_petani_skor'); + Schema::dropIfExists('riwayat_survey_sertifikasi'); + Schema::dropIfExists('riwayat_survey_pelatihan'); + Schema::dropIfExists('riwayat_harga_jual_panen'); + Schema::dropIfExists('riwayat_akses_pasar'); + Schema::dropIfExists('riwayat_pendapatan_luar_pertanian'); + Schema::dropIfExists('riwayat_pendapatan_komoditas'); + Schema::dropIfExists('riwayat_sosial_ekonomi'); + Schema::dropIfExists('riwayat_survey_produktivitas'); + Schema::dropIfExists('riwayat_survey_panen'); + Schema::dropIfExists('riwayat_praktik_budidaya'); + Schema::dropIfExists('riwayat_map_tanaman'); + Schema::dropIfExists('riwayat_sertifikat_lahan'); + Schema::dropIfExists('riwayat_map_lahan'); + } +}; \ No newline at end of file