osb/app/Models/PaymentItem.php
2022-06-13 15:46:38 +10:00

38 lines
627 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Traits\PushNew;
class PaymentItem extends Model
{
use PushNew;
public $timestamps = FALSE;
/* RELATIONS */
public function invoice()
{
return $this->belongsTo(Invoice::class);
}
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;
}
}