osb/app/Models/PaymentItem.php
2021-07-23 17:36:53 +10:00

36 lines
662 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Traits\{NextKey,PushNew};
class PaymentItem extends Model
{
use PushNew;
const RECORD_ID = 'payment_item';
protected $dateFormat = 'U';
const CREATED_AT = 'date_orig';
const UPDATED_AT = 'date_last';
/* RELATIONS */
public function payment() {
return $this->belongsTo(Payment::class);
}
/* ATTRIBUTES */
/**
* If our amount is negative, and invoice_id is null, then this is a reversal.
*
* @param $value
* @return float
*/
public function getAllocAmtAttribute($value): float
{
return (is_null($this->invoice_id) && $value < 0) ? -$value : $value;
}
}