Model and Migration files
This commit is contained in:
@@ -14,17 +14,17 @@ class Distribution extends Model
|
|||||||
|
|
||||||
// Karena id adalah BIGINT auto-increment, default Laravel sudah benar (incrementing = true)
|
// Karena id adalah BIGINT auto-increment, default Laravel sudah benar (incrementing = true)
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'farmer_id', 'farmer_name', 'offtaker_id', 'offtaker_name',
|
'petani_id','panen_uid', 'nama_pengirim', 'offtaker_id', 'nama_offtaker',
|
||||||
'commodity_name', 'quantity_kg', 'farmer_grade', 'offtaker_grade',
|
'komoditas_id', 'berat_kg', 'grade_petani', 'grade_offtaker',
|
||||||
'grade_difference_reason', 'price_per_kg', 'total_value',
|
'alasan_perbedaan_grade', 'harga_per_kg', 'total',
|
||||||
'distribution_date', 'received_date', 'notes', 'status',
|
'tgl_distribusi', 'tgl_terima', 'catatan', 'status',
|
||||||
'sync_status', 'created_date', 'updated_date'
|
'sync_status', 'created_date', 'updated_date',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'quantity_kg' => 'float',
|
'berat_kg' => 'float',
|
||||||
'price_per_kg' => 'float',
|
'harga_per_kg' => 'float',
|
||||||
'total_value' => 'float',
|
'total' => 'float',
|
||||||
'created_date' => 'datetime',
|
'created_date' => 'datetime',
|
||||||
'updated_date' => 'datetime',
|
'updated_date' => 'datetime',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ class InsLahan extends Model
|
|||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $table = 'inspeksi_lahan';
|
protected $table = 'lahan_inspeksi';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'petani_id',
|
'petani_id',
|
||||||
'lahan_id',
|
'lahan_id',
|
||||||
'kadar_air',
|
'kadar_air',
|
||||||
|
'lahan_uid',
|
||||||
'ph',
|
'ph',
|
||||||
'kelembapan',
|
'kelembapan',
|
||||||
'temperatur',
|
'temperatur',
|
||||||
@@ -22,6 +23,7 @@ class InsLahan extends Model
|
|||||||
'catatan',
|
'catatan',
|
||||||
'foto_url',
|
'foto_url',
|
||||||
'sync_status',
|
'sync_status',
|
||||||
|
'tgl_inspeksi',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at'
|
'updated_at'
|
||||||
];
|
];
|
||||||
@@ -30,6 +32,7 @@ class InsLahan extends Model
|
|||||||
'temperatur' => 'float',
|
'temperatur' => 'float',
|
||||||
'kelembapan' => 'float',
|
'kelembapan' => 'float',
|
||||||
'created_at' => 'datetime',
|
'created_at' => 'datetime',
|
||||||
|
'tgl_inspeksi' => 'datetime'
|
||||||
];
|
];
|
||||||
|
|
||||||
public $timestamps = true;
|
public $timestamps = true;
|
||||||
|
|||||||
@@ -15,13 +15,14 @@ class Inspeksi extends Model{
|
|||||||
"tanaman_id",
|
"tanaman_id",
|
||||||
"lahan_id",
|
"lahan_id",
|
||||||
"petani_id",
|
"petani_id",
|
||||||
"inspection_date",
|
"tanaman_uid",
|
||||||
"health_status",
|
"tgl_inspeksi",
|
||||||
"productivity_status",
|
"status_tanaman", // sehat, sakit
|
||||||
"issue_type",
|
"produktifitas", // produktif, kurang dan tidak
|
||||||
"issue_description",
|
"masalah", // hama, kurang air dll
|
||||||
"recommendation",
|
"deskripsi",
|
||||||
"notes",
|
"tindakan", // tindakan apa yang disarankan
|
||||||
|
"catatan",
|
||||||
"created_date",
|
"created_date",
|
||||||
"sync_status"
|
"sync_status"
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -36,4 +36,9 @@ class Lahan extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Tanaman::class, 'lahan_id');
|
return $this->hasMany(Tanaman::class, 'lahan_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function panens(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Panen::class, 'lahan_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ class Panen extends Model
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'uid', // PN-1234567890-1234567890-1234567890 (lahan-tanaman-panen)
|
'uid', // PN-1234567890-1234567890-1234567890 (lahan-tanaman-panen)
|
||||||
// 'plant_id',
|
// 'plant_id',
|
||||||
'title',
|
'judul',
|
||||||
'land_id',
|
'lahan_id',
|
||||||
'farmer_id',
|
'petani_id',
|
||||||
'land_description',
|
'deskripsi',
|
||||||
'harvest_date',
|
'tgl_panen',
|
||||||
'notes',
|
'catatan',
|
||||||
'sync_status',
|
'sync_status',
|
||||||
'created_by',
|
'created_by',
|
||||||
'updated_by',
|
'updated_by',
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ class PanenTanaman extends Model
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
"panen_id",
|
"panen_id",
|
||||||
"tanaman_id",
|
"tanaman_id",
|
||||||
"commodity_name",
|
"komoditas_id",
|
||||||
"sync_status",
|
"sync_status",
|
||||||
"weight_kg"
|
"berat_kg"
|
||||||
];
|
];
|
||||||
|
|
||||||
public function panen(): BelongsTo
|
public function panen(): BelongsTo
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ class Tanaman extends Model
|
|||||||
'komoditas_id',
|
'komoditas_id',
|
||||||
'profile_id',
|
'profile_id',
|
||||||
'lahan_id',
|
'lahan_id',
|
||||||
|
'uid', // TN-1234567890-1234567890-1234567890 (lahan-tanaman-panen)
|
||||||
|
'komoditas_kode',
|
||||||
'latitude',
|
'latitude',
|
||||||
'longitude',
|
'longitude',
|
||||||
'kondisi_tanaman',
|
'kondisi_tanaman',
|
||||||
@@ -33,7 +35,7 @@ class Tanaman extends Model
|
|||||||
|
|
||||||
public function komoditas()
|
public function komoditas()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Komoditas::class, 'komoditas_id');
|
return $this->belongsTo(\App\Models\Pertanian\Komoditas::class, 'komoditas_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function panen()
|
public function panen()
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ return new class extends Migration {
|
|||||||
$table->id();
|
$table->id();
|
||||||
$table->string('uid')->unique()->nullable(); // Bagus untuk sinkronisasi Dexie offline
|
$table->string('uid')->unique()->nullable(); // Bagus untuk sinkronisasi Dexie offline
|
||||||
$table->string('title'); // Judul aktivitas panen
|
$table->string('title'); // Judul aktivitas panen
|
||||||
$table->unsignedBigInteger('land_id')->nullable();
|
$table->unsignedBigInteger('lahan_id')->nullable();
|
||||||
$table->unsignedBigInteger('farmer_id')->nullable();
|
$table->unsignedBigInteger('petani_id')->nullable();
|
||||||
$table->text('land_description')->nullable(); // Deskripsi kondisi lahan saat panen
|
$table->text('deskripsi')->nullable(); // Deskripsi kondisi lahan saat panen
|
||||||
$table->date('harvest_date');
|
$table->date('tgl_panen');
|
||||||
$table->text('notes')->nullable();
|
$table->text('catatan')->nullable();
|
||||||
$table->string('sync_status')->default('pending');
|
$table->string('sync_status')->default('pending');
|
||||||
|
|
||||||
// Audit Columns
|
// Audit Columns
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ return new class extends Migration {
|
|||||||
$table->unsignedBigInteger('tanaman_id')->nullable();
|
$table->unsignedBigInteger('tanaman_id')->nullable();
|
||||||
$table->unsignedBigInteger('lahan_id')->nullable();
|
$table->unsignedBigInteger('lahan_id')->nullable();
|
||||||
$table->unsignedBigInteger('petani_id')->nullable();
|
$table->unsignedBigInteger('petani_id')->nullable();
|
||||||
$table->date('inspection_date')->nullable();
|
$table->string('tanaman_uid');
|
||||||
$table->string('health_status')->nullable();
|
$table->date('tgl_inspeksi')->nullable();
|
||||||
$table->string('productivity_status')->nullable();
|
$table->string('status_tanaman')->nullable();
|
||||||
$table->string('issue_type')->nullable();
|
$table->string('produktifitas')->nullable();
|
||||||
$table->text('issue_description')->nullable();
|
$table->string('masalah')->nullable();
|
||||||
$table->text('recommendation')->nullable();
|
$table->text('deskripsi')->nullable();
|
||||||
$table->text('notes')->nullable();
|
$table->text('tindakan')->nullable();
|
||||||
|
$table->text('catatan')->nullable();
|
||||||
$table->string('sync_status')->default('pending');
|
$table->string('sync_status')->default('pending');
|
||||||
|
|
||||||
// Audit Columns
|
// Audit Columns
|
||||||
|
|||||||
@@ -6,15 +6,17 @@ use Illuminate\Support\Facades\Schema;
|
|||||||
|
|
||||||
return new class extends Migration {
|
return new class extends Migration {
|
||||||
public function up(): void {
|
public function up(): void {
|
||||||
Schema::create('inspeksi_lahan', function (Blueprint $table) {
|
Schema::create('lahan_inspeksi', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('petani_id')->nullable()->constrained('users')->onDelete('set null');
|
$table->foreignId('petani_id')->nullable()->constrained('users')->onDelete('set null');
|
||||||
$table->unsignedBigInteger('lahan_id')->nullable();
|
$table->unsignedBigInteger('lahan_id')->nullable();
|
||||||
|
$table->string('lahan_uid');
|
||||||
$table->double('kadar_air')->nullable();
|
$table->double('kadar_air')->nullable();
|
||||||
$table->double('ph')->nullable();
|
$table->double('ph')->nullable();
|
||||||
$table->double('kelembapan')->nullable();
|
$table->double('kelembapan')->nullable();
|
||||||
$table->double('temperatur')->nullable();
|
$table->double('temperatur')->nullable();
|
||||||
$table->string('kondisi_tanaman')->nullable();
|
$table->string('kondisi_tanaman')->nullable();
|
||||||
|
$table->date('tgl_inspeksi');
|
||||||
$table->text('catatan')->nullable();
|
$table->text('catatan')->nullable();
|
||||||
$table->string('foto_url')->nullable();
|
$table->string('foto_url')->nullable();
|
||||||
$table->string('sync_status')->default('pending');
|
$table->string('sync_status')->default('pending');
|
||||||
|
|||||||
@@ -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
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('master_komoditas', function (Blueprint $table) {
|
||||||
|
$table->string('kode')->unique();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('master_komoditas', function (Blueprint $table) {
|
||||||
|
$table->dropUnique('kode');
|
||||||
|
$table->dropColumn('kode');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?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('panen_komoditas', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('uid')->unique()->nullable();
|
||||||
|
$table->foreignId('panen_id')->constrained('map_panen')->onDelete('cascade');
|
||||||
|
|
||||||
|
$table->unsignedBigInteger('plant_id')->nullable(); // ID Tanaman (tanaman_id)
|
||||||
|
$table->integer('komoditas_id'); // Nama komoditas
|
||||||
|
$table->double('weight_kg')->default(0); // Berat hasil panen (panen_kg)
|
||||||
|
$table->string('sync_status')->default('pending');
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
$table->softDeletes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('panen_komoditas');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -19,9 +19,9 @@ return new class extends Migration
|
|||||||
->onDelete('cascade');
|
->onDelete('cascade');
|
||||||
|
|
||||||
$bluePrint->unsignedBigInteger('tanaman_id')->nullable();
|
$bluePrint->unsignedBigInteger('tanaman_id')->nullable();
|
||||||
$bluePrint->string('commodity_name');
|
$bluePrint->string('komoditas_id');
|
||||||
$bluePrint->string('sync_status', 50)->nullable()->default('synced');
|
$bluePrint->string('sync_status', 50)->nullable()->default('synced');
|
||||||
$bluePrint->decimal('weight_kg', 10, 2); // Menggunakan decimal agar mendukung angka pecahan (misal: 10.5 kg)
|
$bluePrint->decimal('berat_kg', 10, 2); // Menggunakan decimal agar mendukung angka pecahan (misal: 10.5 kg)
|
||||||
|
|
||||||
$bluePrint->timestamps();
|
$bluePrint->timestamps();
|
||||||
$bluePrint->softDeletes(); // Menambahkan kolom deleted_at untuk fitur SoftDeletes
|
$bluePrint->softDeletes(); // Menambahkan kolom deleted_at untuk fitur SoftDeletes
|
||||||
|
|||||||
Reference in New Issue
Block a user