76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
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 App\Models\Pertanian\Petani;
|
|
|
|
class SurveyPanen extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'survey_panen';
|
|
|
|
protected $fillable = [
|
|
'uid',
|
|
'petani_id',
|
|
'dasar_penentuan_panen',
|
|
'frekuensi_panen_pertahun',
|
|
'bulan_panen_utama',
|
|
'hasil_komoditas_utama_permusim',
|
|
'hasil_komoditas_lainnya_permusim',
|
|
'disimpan_untuk_sendiri',
|
|
'hasil_panen_disimpan',
|
|
'tujuan_disimpan',
|
|
'praktik_sortasi',
|
|
'bentuk_sortasi',
|
|
'hasil_panen_reject',
|
|
'jumlah_panen_reject',
|
|
'tindakan_panen_reject',
|
|
'upah_tenaga_panen',
|
|
'biaya_pengangkutan_panen',
|
|
'biaya_wadah_panen',
|
|
'biaya_sewa_alat_panen',
|
|
'biaya_panen_lainnya',
|
|
'total_estimasi_biaya_panen',
|
|
'estimasi_kehilangan_akibat_opt',
|
|
'estimasi_kehilangan_akibat_hama_penyakit',
|
|
'created_by',
|
|
'updated_by',
|
|
'deleted_by',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::saved(function (SurveyPanen $survey) {
|
|
|
|
$petani = Petani::find($survey->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_k3_1_penentuan_pematangan' => $survey->dasar_penentuan_panen,
|
|
'skor_d2_k3_5_sortasi_awal_pemisahan_kualitas' => $survey->praktik_sortasi,
|
|
]);
|
|
});
|
|
}
|
|
|
|
public function petani(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Petani::class, 'petani_id');
|
|
}
|
|
}
|