SIPDAM/samooapk/laravel/app/Models/TarifPekerjaan.php

61 lines
1.5 KiB
PHP

<?php
// app/Models/TarifPekerjaan.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class TarifPekerjaan extends Model
{
use SoftDeletes;
protected $table = 'tarif_pekerjaans';
protected $primaryKey = 'id_tarif';
protected $fillable = [
'jenis_pekerjaan',
'nama_item',
'kode_item',
'dimensi_pipa',
'tarif_per_unit',
'tarif_per_meter',
'pakai_pipa_besi',
'ada_garansi',
'durasi_garansi_bulan',
'deskripsi',
'is_active',
];
protected $casts = [
'tarif_per_unit' => 'decimal:2',
'tarif_per_meter' => 'decimal:2',
'pakai_pipa_besi' => 'boolean',
'ada_garansi' => 'boolean',
'is_active' => 'boolean',
];
// Accessor: ambil harga (tarif_per_unit atau tarif_per_meter)
public function getHargaAttribute(): float
{
return (float) ($this->tarif_per_unit ?? $this->tarif_per_meter ?? 0);
}
// Relationship
public function penugasans()
{
return $this->hasMany(Penugasan::class, 'id_tarif', 'id_tarif');
}
// Scope untuk filter aktif
public function scopeActive($query)
{
return $query->where('is_active', true);
}
// Scope untuk filter by kategori
public function scopeKategori($query, $kategori)
{
return $query->where('kategori', $kategori);
}
}