feat: add AnggotaKeluarga, RiwayatBantuan, PermohonanTransfer models and migrations
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AnggotaKeluarga extends Model
|
||||
{
|
||||
protected $table = 'anggota_keluarga';
|
||||
protected $fillable = [
|
||||
'id_rumah', 'nama', 'hubungan', 'jenis_kelamin',
|
||||
'tanggal_lahir', 'pendidikan', 'status_hidup',
|
||||
];
|
||||
protected $casts = ['tanggal_lahir' => '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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PermohonanTransfer extends Model
|
||||
{
|
||||
protected $table = 'permohonan_transfer';
|
||||
protected $fillable = [
|
||||
'dari_ibadah_id', 'ke_ibadah_id', 'id_rumah',
|
||||
'alasan', 'status', 'catatan_respons',
|
||||
'diajukan_oleh', 'diproses_oleh',
|
||||
];
|
||||
|
||||
public function dariIbadah() { return $this->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'); }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RiwayatBantuan extends Model
|
||||
{
|
||||
protected $table = 'riwayat_bantuan';
|
||||
protected $fillable = [
|
||||
'id_rumah', 'ibadah_id', 'dicatat_oleh',
|
||||
'jenis_bantuan', 'keterangan', 'tanggal_bantuan',
|
||||
];
|
||||
protected $casts = ['tanggal_bantuan' => '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'); }
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('anggota_keluarga', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('riwayat_bantuan', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('permohonan_transfer', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user