Merge branch 'main' of https://git.probindo.com/Probindo/database-pertani-web
This commit is contained in:
@@ -2,24 +2,20 @@
|
||||
|
||||
namespace App\Models\Pertanian;
|
||||
|
||||
use App\Enums\Pendidikan;
|
||||
use App\Enums\Pernikahan;
|
||||
use App\Models\Wilayah\DesaKelurahan;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use App\Models\Wilayah\DesaKelurahan;
|
||||
use App\Enums\Pendidikan;
|
||||
use App\Enums\Pernikahan;
|
||||
|
||||
use App\Models\Pertanian\SkorPetani;
|
||||
|
||||
class Petani extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'petani';
|
||||
|
||||
@@ -29,19 +25,19 @@ class Petani extends Model
|
||||
|
||||
'nomor_telepon',
|
||||
'alamat',
|
||||
|
||||
|
||||
'kk',
|
||||
'ktp',
|
||||
'uid',
|
||||
'desa_kelurahan_id',
|
||||
|
||||
'foto',
|
||||
|
||||
|
||||
'path_kk',
|
||||
'file_kk',
|
||||
'path_ktp',
|
||||
'file_ktp',
|
||||
|
||||
|
||||
'jenis_kelamin',
|
||||
'tempat_lahir',
|
||||
'tanggal_lahir',
|
||||
@@ -50,7 +46,7 @@ class Petani extends Model
|
||||
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by'
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@@ -63,7 +59,7 @@ class Petani extends Model
|
||||
|
||||
public function getUmurAttribute(): ?int
|
||||
{
|
||||
if (!$this->tanggal_lahir) {
|
||||
if (! $this->tanggal_lahir) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -85,13 +81,13 @@ class Petani extends Model
|
||||
static::saved(function (Petani $petani) {
|
||||
|
||||
$skor = SkorPetani::where('petani_id')->orderBy('id')->first();
|
||||
if (!$skor) {
|
||||
if (! $skor) {
|
||||
$petaniUid = $petani->uid;
|
||||
$part = explode('-', $petaniUid);
|
||||
$skor = SkorPetani::create([
|
||||
'uid' => 'SKR-' . $part[1] . '-' . strtoupper(Str::random(10)),
|
||||
'uid' => 'SKR-'.$part[1].'-'.strtoupper(Str::random(10)),
|
||||
'created_by' => $petani->created_by,
|
||||
'updated_by' => $petani->updated_by
|
||||
'updated_by' => $petani->updated_by,
|
||||
]);
|
||||
}
|
||||
});
|
||||
@@ -134,7 +130,7 @@ class Petani extends Model
|
||||
|
||||
public function skorLahanTanaman(): ?float
|
||||
{
|
||||
if (!Schema::hasTable('map_lahan')) {
|
||||
if (! Schema::hasTable('map_lahan')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -152,7 +148,7 @@ class Petani extends Model
|
||||
'mati' => 0,
|
||||
default => null,
|
||||
})
|
||||
->filter(fn ($value) => !is_null($value));
|
||||
->filter(fn ($value) => ! is_null($value));
|
||||
|
||||
if ($nilaiKondisi->isEmpty()) {
|
||||
return null;
|
||||
@@ -163,13 +159,13 @@ class Petani extends Model
|
||||
|
||||
public function skorPraktikBudidaya(): ?float
|
||||
{
|
||||
if (!Schema::hasTable('praktik_budidaya')) {
|
||||
if (! Schema::hasTable('praktik_budidaya')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$praktikBudidaya = $this->praktikBudidaya()->first();
|
||||
|
||||
if (!$praktikBudidaya) {
|
||||
if (! $praktikBudidaya) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -181,7 +177,7 @@ class Petani extends Model
|
||||
$praktikBudidaya->penanganan_gulma,
|
||||
$praktikBudidaya->kondisi_pengelolaan_air,
|
||||
$praktikBudidaya->nilai_konservasi_tanah,
|
||||
])->filter(fn ($value) => !is_null($value) && $value !== '');
|
||||
])->filter(fn ($value) => ! is_null($value) && $value !== '');
|
||||
|
||||
if ($nilai->isEmpty()) {
|
||||
return null;
|
||||
@@ -192,7 +188,7 @@ class Petani extends Model
|
||||
|
||||
public function skorPendidikan(): ?float
|
||||
{
|
||||
if (!$this->pendidikan_terakhir) {
|
||||
if (! $this->pendidikan_terakhir) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -215,13 +211,13 @@ class Petani extends Model
|
||||
|
||||
public function skorSosialEkonomi(): ?float
|
||||
{
|
||||
if (!Schema::hasTable('sosial_ekonomi')) {
|
||||
if (! Schema::hasTable('sosial_ekonomi')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sosialEkonomi = $this->sosialEkonomi()->first();
|
||||
|
||||
if (!$sosialEkonomi) {
|
||||
if (! $sosialEkonomi) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -245,7 +241,7 @@ class Petani extends Model
|
||||
$this->enumValue($sosialEkonomi->keterikatan_hutang_panen),
|
||||
$this->enumValue($sosialEkonomi->praktik_ijon),
|
||||
$this->enumValue($sosialEkonomi->kebebasan_memilih_pembeli),
|
||||
])->filter(fn ($value) => !is_null($value) && $value !== '' && (int) $value > 0);
|
||||
])->filter(fn ($value) => ! is_null($value) && $value !== '' && (int) $value > 0);
|
||||
|
||||
if ($nilai->isEmpty()) {
|
||||
return null;
|
||||
@@ -256,20 +252,20 @@ class Petani extends Model
|
||||
|
||||
public function skorAksesPasar(): ?float
|
||||
{
|
||||
if (!Schema::hasTable('akses_pasar')) {
|
||||
if (! Schema::hasTable('akses_pasar')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$aksesPasar = $this->aksesPasar()->first();
|
||||
|
||||
if (!$aksesPasar) {
|
||||
if (! $aksesPasar) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$nilai = collect(Schema::getColumnListing($aksesPasar->getTable()))
|
||||
->filter(fn ($field) => str_starts_with($field, 'skor_'))
|
||||
->map(fn ($field) => $aksesPasar->getAttribute($field))
|
||||
->filter(fn ($value) => !is_null($value) && $value !== '');
|
||||
->filter(fn ($value) => ! is_null($value) && $value !== '');
|
||||
|
||||
if ($nilai->isEmpty()) {
|
||||
return null;
|
||||
@@ -286,7 +282,7 @@ class Petani extends Model
|
||||
$this->skorPendidikan(),
|
||||
$this->skorSosialEkonomi(),
|
||||
$this->skorAksesPasar(),
|
||||
])->filter(fn ($value) => !is_null($value));
|
||||
])->filter(fn ($value) => ! is_null($value));
|
||||
|
||||
if ($nilai->isEmpty()) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user