From e9071001757cdbb1657548613f8aedd20a56be70 Mon Sep 17 00:00:00 2001 From: GuavaPopper Date: Fri, 5 Jun 2026 04:52:23 +0700 Subject: [PATCH] feat: add AnggotaKeluarga, RiwayatBantuan, PermohonanTransfer models and migrations Co-Authored-By: Claude Sonnet 4.6 --- app/Models/AnggotaKeluarga.php | 28 +++++++++++++++++ app/Models/PermohonanTransfer.php | 21 +++++++++++++ app/Models/RiwayatBantuan.php | 19 ++++++++++++ app/Models/RumahIbadah.php | 5 +++ app/Models/RumahMiskin.php | 12 ++++++- ...05_02_062948_create_rumah_ibadah_table.php | 7 ++++- ...05_02_062949_create_rumah_miskin_table.php | 5 +++ ...026_05_19_033727_create_sessions_table.php | 31 +++++++++++++++++++ ...5_000001_create_anggota_keluarga_table.php | 28 +++++++++++++++++ ...05_000002_create_riwayat_bantuan_table.php | 27 ++++++++++++++++ ...00003_create_permohonan_transfer_table.php | 29 +++++++++++++++++ 11 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 app/Models/AnggotaKeluarga.php create mode 100644 app/Models/PermohonanTransfer.php create mode 100644 app/Models/RiwayatBantuan.php create mode 100644 database/migrations/2026_05_19_033727_create_sessions_table.php create mode 100644 database/migrations/2026_06_05_000001_create_anggota_keluarga_table.php create mode 100644 database/migrations/2026_06_05_000002_create_riwayat_bantuan_table.php create mode 100644 database/migrations/2026_06_05_000003_create_permohonan_transfer_table.php diff --git a/app/Models/AnggotaKeluarga.php b/app/Models/AnggotaKeluarga.php new file mode 100644 index 0000000..306e23e --- /dev/null +++ b/app/Models/AnggotaKeluarga.php @@ -0,0 +1,28 @@ + 'date']; + + public function rumahMiskin() + { + return $this->belongsTo(RumahMiskin::class, 'id_rumah', 'id_rumah'); + } + + public function getUmurAttribute(): ?int + { + return $this->tanggal_lahir + ? now()->diffInYears(Carbon::parse($this->tanggal_lahir)) + : null; + } +} diff --git a/app/Models/PermohonanTransfer.php b/app/Models/PermohonanTransfer.php new file mode 100644 index 0000000..89df498 --- /dev/null +++ b/app/Models/PermohonanTransfer.php @@ -0,0 +1,21 @@ +belongsTo(RumahIbadah::class, 'dari_ibadah_id'); } + public function keIbadah() { return $this->belongsTo(RumahIbadah::class, 'ke_ibadah_id'); } + public function rumahMiskin() { return $this->belongsTo(RumahMiskin::class, 'id_rumah', 'id_rumah'); } + public function pengaju() { return $this->belongsTo(User::class, 'diajukan_oleh'); } + public function pemroses() { return $this->belongsTo(User::class, 'diproses_oleh'); } +} diff --git a/app/Models/RiwayatBantuan.php b/app/Models/RiwayatBantuan.php new file mode 100644 index 0000000..7e0b868 --- /dev/null +++ b/app/Models/RiwayatBantuan.php @@ -0,0 +1,19 @@ + 'date']; + + public function rumahMiskin() { return $this->belongsTo(RumahMiskin::class, 'id_rumah', 'id_rumah'); } + public function ibadah() { return $this->belongsTo(RumahIbadah::class, 'ibadah_id'); } + public function pencatat() { return $this->belongsTo(User::class, 'dicatat_oleh'); } +} diff --git a/app/Models/RumahIbadah.php b/app/Models/RumahIbadah.php index b913788..0806236 100644 --- a/app/Models/RumahIbadah.php +++ b/app/Models/RumahIbadah.php @@ -17,4 +17,9 @@ class RumahIbadah extends Model { return $this->belongsTo(\App\Models\User::class); } + + public function bantuanDiberikan() + { + return $this->hasMany(RiwayatBantuan::class, 'ibadah_id'); + } } diff --git a/app/Models/RumahMiskin.php b/app/Models/RumahMiskin.php index dd2a354..56533b4 100644 --- a/app/Models/RumahMiskin.php +++ b/app/Models/RumahMiskin.php @@ -14,5 +14,15 @@ class RumahMiskin extends Model protected $primaryKey = 'id_rumah'; public $incrementing = false; protected $keyType = 'string'; - protected $fillable = ['id_rumah', 'alamat', 'jumlah_kk', 'jumlah_orang', 'latitude', 'longitude']; + protected $fillable = ['id_rumah', 'nama_kk', 'alamat', 'jumlah_kk', 'jumlah_orang', 'latitude', 'longitude', 'pekerjaan', 'pendapatan', 'kondisi_rumah', 'keterangan']; + + public function anggota() + { + return $this->hasMany(AnggotaKeluarga::class, 'id_rumah', 'id_rumah'); + } + + public function bantuan() + { + return $this->hasMany(RiwayatBantuan::class, 'id_rumah', 'id_rumah'); + } } diff --git a/database/migrations/2026_05_02_062948_create_rumah_ibadah_table.php b/database/migrations/2026_05_02_062948_create_rumah_ibadah_table.php index d90abc5..ff6c8cb 100644 --- a/database/migrations/2026_05_02_062948_create_rumah_ibadah_table.php +++ b/database/migrations/2026_05_02_062948_create_rumah_ibadah_table.php @@ -14,10 +14,15 @@ return new class extends Migration Schema::create('rumah_ibadah', function (Blueprint $table) { $table->id(); $table->string('nama'); - $table->text('alamat'); + $table->string('jenis')->nullable(); // masjid, gereja, pura, klenteng, vihara + $table->text('alamat')->nullable(); $table->decimal('latitude', 10, 8); $table->decimal('longitude', 11, 8); $table->integer('radius')->default(500); + $table->integer('jumlah_jemaah')->nullable(); + $table->string('pengurus')->nullable(); + $table->string('telepon')->nullable(); + $table->text('keterangan')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/2026_05_02_062949_create_rumah_miskin_table.php b/database/migrations/2026_05_02_062949_create_rumah_miskin_table.php index 13c21ff..8672dbb 100644 --- a/database/migrations/2026_05_02_062949_create_rumah_miskin_table.php +++ b/database/migrations/2026_05_02_062949_create_rumah_miskin_table.php @@ -13,11 +13,16 @@ return new class extends Migration { Schema::create('rumah_miskin', function (Blueprint $table) { $table->string('id_rumah', 50)->primary(); + $table->string('nama_kk')->nullable(); // Adding this as per SRS $table->text('alamat')->nullable(); $table->integer('jumlah_kk')->default(1); $table->integer('jumlah_orang')->default(1); $table->decimal('latitude', 10, 8); $table->decimal('longitude', 11, 8); + $table->string('pekerjaan')->nullable(); + $table->bigInteger('pendapatan')->nullable(); + $table->string('kondisi_rumah')->nullable(); // sangat_buruk, buruk, sedang + $table->text('keterangan')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/2026_05_19_033727_create_sessions_table.php b/database/migrations/2026_05_19_033727_create_sessions_table.php new file mode 100644 index 0000000..f60625b --- /dev/null +++ b/database/migrations/2026_05_19_033727_create_sessions_table.php @@ -0,0 +1,31 @@ +string('id')->primary(); + $table->foreignId('user_id')->nullable()->index(); + $table->string('ip_address', 45)->nullable(); + $table->text('user_agent')->nullable(); + $table->longText('payload'); + $table->integer('last_activity')->index(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('sessions'); + } +}; diff --git a/database/migrations/2026_06_05_000001_create_anggota_keluarga_table.php b/database/migrations/2026_06_05_000001_create_anggota_keluarga_table.php new file mode 100644 index 0000000..244803e --- /dev/null +++ b/database/migrations/2026_06_05_000001_create_anggota_keluarga_table.php @@ -0,0 +1,28 @@ +id(); + $table->string('id_rumah', 50); + $table->foreign('id_rumah')->references('id_rumah')->on('rumah_miskin')->cascadeOnDelete(); + $table->string('nama'); + $table->enum('hubungan', ['kepala_keluarga', 'istri', 'anak', 'orang_tua', 'lainnya'])->default('lainnya'); + $table->enum('jenis_kelamin', ['laki_laki', 'perempuan'])->nullable(); + $table->date('tanggal_lahir')->nullable(); + $table->enum('pendidikan', ['tidak_sekolah', 'sd', 'smp', 'sma', 'd3', 's1_plus'])->nullable(); + $table->enum('status_hidup', ['hidup', 'meninggal'])->default('hidup'); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('anggota_keluarga'); + } +}; diff --git a/database/migrations/2026_06_05_000002_create_riwayat_bantuan_table.php b/database/migrations/2026_06_05_000002_create_riwayat_bantuan_table.php new file mode 100644 index 0000000..c7cce95 --- /dev/null +++ b/database/migrations/2026_06_05_000002_create_riwayat_bantuan_table.php @@ -0,0 +1,27 @@ +id(); + $table->string('id_rumah', 50); + $table->foreign('id_rumah')->references('id_rumah')->on('rumah_miskin')->cascadeOnDelete(); + $table->foreignId('ibadah_id')->nullable()->constrained('rumah_ibadah')->nullOnDelete(); + $table->foreignId('dicatat_oleh')->nullable()->constrained('users')->nullOnDelete(); + $table->string('jenis_bantuan'); + $table->text('keterangan')->nullable(); + $table->date('tanggal_bantuan'); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('riwayat_bantuan'); + } +}; diff --git a/database/migrations/2026_06_05_000003_create_permohonan_transfer_table.php b/database/migrations/2026_06_05_000003_create_permohonan_transfer_table.php new file mode 100644 index 0000000..6502d20 --- /dev/null +++ b/database/migrations/2026_06_05_000003_create_permohonan_transfer_table.php @@ -0,0 +1,29 @@ +id(); + $table->foreignId('dari_ibadah_id')->constrained('rumah_ibadah')->cascadeOnDelete(); + $table->foreignId('ke_ibadah_id')->constrained('rumah_ibadah')->cascadeOnDelete(); + $table->string('id_rumah', 50); + $table->foreign('id_rumah')->references('id_rumah')->on('rumah_miskin')->cascadeOnDelete(); + $table->text('alasan'); + $table->enum('status', ['pending', 'disetujui', 'ditolak'])->default('pending'); + $table->text('catatan_respons')->nullable(); + $table->foreignId('diajukan_oleh')->constrained('users')->cascadeOnDelete(); + $table->foreignId('diproses_oleh')->nullable()->constrained('users')->nullOnDelete(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('permohonan_transfer'); + } +};