51 lines
993 B
PHP
51 lines
993 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use App\Traits\PushNew;
|
|
use App\Traits\NextKey;
|
|
|
|
class Payment extends Model
|
|
{
|
|
use NextKey,PushNew;
|
|
const RECORD_ID = 'payment';
|
|
public $incrementing = FALSE;
|
|
|
|
const CREATED_AT = 'date_orig';
|
|
const UPDATED_AT = 'date_last';
|
|
|
|
protected $table = 'ab_payment';
|
|
protected $dates = ['date_payment'];
|
|
protected $dateFormat = 'U';
|
|
protected $with = ['account.country.currency','items'];
|
|
|
|
// Array of items that can be updated with PushNew
|
|
protected $pushable = ['items'];
|
|
|
|
public function account()
|
|
{
|
|
return $this->belongsTo(Account::class);
|
|
}
|
|
|
|
public function items()
|
|
{
|
|
return $this->hasMany(PaymentItem::class);
|
|
}
|
|
|
|
public function getDatePaidAttribute()
|
|
{
|
|
return $this->date_payment->format('Y-m-d');
|
|
}
|
|
|
|
public function getTotalAttribute()
|
|
{
|
|
return sprintf('%3.'.$this->currency()->rounding.'f',$this->total_amt);
|
|
}
|
|
|
|
public function currency()
|
|
{
|
|
return $this->account->country->currency;
|
|
}
|
|
} |