2018-05-20 12:53:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Payment extends Model
|
|
|
|
{
|
|
|
|
protected $table = 'ab_payment';
|
|
|
|
protected $dates = ['date_payment'];
|
2018-06-19 12:31:49 +00:00
|
|
|
protected $with = ['account.country.currency','items'];
|
2018-05-20 12:53:14 +00:00
|
|
|
|
2018-06-19 12:31:49 +00:00
|
|
|
protected $appends = [
|
|
|
|
'date_paid',
|
2018-07-16 05:06:43 +00:00
|
|
|
'payment_id_url',
|
2018-06-19 12:31:49 +00:00
|
|
|
'total',
|
|
|
|
];
|
|
|
|
|
|
|
|
protected $visible = [
|
|
|
|
'date_paid',
|
|
|
|
'id',
|
2018-07-16 05:06:43 +00:00
|
|
|
'payment_id_url',
|
2018-06-19 12:31:49 +00:00
|
|
|
'total',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function account()
|
|
|
|
{
|
2018-07-13 04:53:44 +00:00
|
|
|
return $this->belongsTo(Account::class);
|
2018-06-19 12:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function items()
|
|
|
|
{
|
|
|
|
return $this->hasMany(PaymentItem::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDatePaidAttribute()
|
2018-05-20 12:53:14 +00:00
|
|
|
{
|
|
|
|
return $this->date_payment->format('Y-m-d');
|
|
|
|
}
|
2018-06-19 12:31:49 +00:00
|
|
|
|
2018-07-16 05:06:43 +00:00
|
|
|
public function getPaymentIdAttribute()
|
|
|
|
{
|
|
|
|
return sprintf('%02s-%04s+%05s',$this->site_id,$this->account_id,$this->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPaymentIdUrlAttribute()
|
|
|
|
{
|
|
|
|
return sprintf('<a href="/u/payment/view/%s">%s</a>',$this->id,$this->payment_id);
|
|
|
|
}
|
|
|
|
|
2018-06-19 12:31:49 +00:00
|
|
|
public function getTotalAttribute()
|
|
|
|
{
|
|
|
|
return sprintf('%3.'.$this->currency()->rounding.'f',$this->total_amt);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function currency()
|
|
|
|
{
|
|
|
|
return $this->account->country->currency;
|
|
|
|
}
|
2018-05-20 12:53:14 +00:00
|
|
|
}
|