osb/app/Models/Payment.php

51 lines
993 B
PHP
Raw Normal View History

2018-05-20 12:53:14 +00:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
2020-07-27 04:49:59 +00:00
use App\Traits\PushNew;
use App\Traits\NextKey;
2018-05-20 12:53:14 +00:00
class Payment extends Model
{
2020-07-27 04:49:59 +00:00
use NextKey,PushNew;
const RECORD_ID = 'payment';
public $incrementing = FALSE;
const CREATED_AT = 'date_orig';
const UPDATED_AT = 'date_last';
2018-05-20 12:53:14 +00:00
protected $table = 'ab_payment';
protected $dates = ['date_payment'];
protected $dateFormat = 'U';
protected $with = ['account.country.currency','items'];
2018-05-20 12:53:14 +00:00
2020-07-27 04:49:59 +00:00
// Array of items that can be updated with PushNew
protected $pushable = ['items'];
public function account()
{
2018-07-13 04:53:44 +00:00
return $this->belongsTo(Account::class);
}
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');
}
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
}