46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\Payment\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\Models\Agent\Agent;
|
|
use App\Models\Company\Company;
|
|
use App\Models\Complex;
|
|
class Payment extends Model
|
|
{
|
|
use HasFactory;
|
|
protected $fillable = [
|
|
'paymentable_type',
|
|
'paymentable_id',
|
|
'complex_id',
|
|
'value'
|
|
];
|
|
public function getPaymentablePercent()
|
|
{
|
|
//наследуется
|
|
if ((int) $this->value == -1)
|
|
{
|
|
if ($this->paymentable_type == 'Company')
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if ($this->paymentable_type == 'Agent')
|
|
{
|
|
$agent = Agent::find($this->paymentable_id);
|
|
$company = $agent->company;
|
|
$parentPaymentable = $company->getPaymentable(Complex::find($this->complex_id));
|
|
return $parentPaymentable->getPaymentablePercent();
|
|
}
|
|
}
|
|
//не установлено
|
|
if ($this->value == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return $this->value;
|
|
}
|
|
}
|