148 lines
3.3 KiB
PHP
148 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\AssetExchange\Models;
|
|
|
|
use App\Business;
|
|
use App\Contact;
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Listing extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'aex_listings';
|
|
|
|
protected $fillable = [
|
|
'business_id',
|
|
'listing_code',
|
|
'seller_contact_id',
|
|
'listing_type',
|
|
'scope_type',
|
|
'title',
|
|
'description',
|
|
'location_text',
|
|
'site_country',
|
|
'year_manufactured',
|
|
'condition_grade',
|
|
'asking_price',
|
|
'currency_id',
|
|
'price_negotiable',
|
|
'visibility',
|
|
'status',
|
|
'manufacturer',
|
|
'model',
|
|
'serial_number',
|
|
'working_hours',
|
|
'specs_json',
|
|
'intake_source',
|
|
'ie_line_template_id',
|
|
'ie_line_revision_id',
|
|
'ie_bom_id',
|
|
'ie_installed_asset_id',
|
|
'maintenance_equipment_id',
|
|
'asset_id',
|
|
'parent_listing_id',
|
|
'photos',
|
|
'documents',
|
|
'assigned_broker_user_id',
|
|
'created_by',
|
|
'submitted_at',
|
|
'appraised_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'year_manufactured' => 'integer',
|
|
'asking_price' => 'integer',
|
|
'price_negotiable' => 'boolean',
|
|
'photos' => 'array',
|
|
'documents' => 'array',
|
|
'specs_json' => 'array',
|
|
'working_hours' => 'integer',
|
|
'submitted_at' => 'datetime',
|
|
'appraised_at' => 'datetime',
|
|
];
|
|
|
|
public function business()
|
|
{
|
|
return $this->belongsTo(Business::class);
|
|
}
|
|
|
|
public function seller()
|
|
{
|
|
return $this->belongsTo(Contact::class, 'seller_contact_id');
|
|
}
|
|
|
|
public function broker()
|
|
{
|
|
return $this->belongsTo(User::class, 'assigned_broker_user_id');
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function parentListing()
|
|
{
|
|
return $this->belongsTo(self::class, 'parent_listing_id');
|
|
}
|
|
|
|
public function childListings()
|
|
{
|
|
return $this->hasMany(self::class, 'parent_listing_id');
|
|
}
|
|
|
|
public function media()
|
|
{
|
|
return $this->hasMany(ListingMedia::class, 'listing_id')->orderBy('sort_order');
|
|
}
|
|
|
|
public function appraisals()
|
|
{
|
|
return $this->hasMany(Appraisal::class, 'listing_id');
|
|
}
|
|
|
|
public function deals()
|
|
{
|
|
return $this->hasMany(Deal::class, 'listing_id');
|
|
}
|
|
|
|
public function offers()
|
|
{
|
|
return $this->hasMany(Offer::class, 'listing_id');
|
|
}
|
|
|
|
public function pipelineLinks()
|
|
{
|
|
return $this->hasMany(PipelineLink::class, 'listing_id');
|
|
}
|
|
|
|
public function marketComps()
|
|
{
|
|
return $this->hasMany(MarketComp::class, 'listing_id');
|
|
}
|
|
|
|
public function catalogMatches()
|
|
{
|
|
return $this->hasMany(CatalogMatch::class, 'listing_id')->orderByDesc('match_score');
|
|
}
|
|
|
|
public function researchCases()
|
|
{
|
|
return $this->hasMany(ResearchCase::class, 'listing_id');
|
|
}
|
|
|
|
public function priceInquiries()
|
|
{
|
|
return $this->hasMany(PriceInquiry::class, 'listing_id');
|
|
}
|
|
|
|
public function pipelineEvents()
|
|
{
|
|
return $this->hasMany(PipelineEvent::class, 'entity_id')
|
|
->where('entity_type', self::class);
|
|
}
|
|
}
|