2018-05-20 12:53:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
2021-07-02 04:35:43 +00:00
|
|
|
use App\Traits\{NextKey,PushNew};
|
2020-07-27 04:49:59 +00:00
|
|
|
|
2018-05-20 12:53:14 +00:00
|
|
|
class PaymentItem extends Model
|
|
|
|
{
|
2021-07-23 07:25:26 +00:00
|
|
|
use PushNew;
|
2020-07-27 04:49:59 +00:00
|
|
|
const RECORD_ID = 'payment_item';
|
|
|
|
|
2021-07-02 04:35:43 +00:00
|
|
|
protected $dateFormat = 'U';
|
2020-07-27 04:49:59 +00:00
|
|
|
const CREATED_AT = 'date_orig';
|
|
|
|
const UPDATED_AT = 'date_last';
|
|
|
|
|
2021-07-02 04:35:43 +00:00
|
|
|
/* RELATIONS */
|
|
|
|
|
2021-10-01 04:59:04 +00:00
|
|
|
public function invoice()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Invoice::class);
|
|
|
|
}
|
|
|
|
|
2020-07-27 04:49:59 +00:00
|
|
|
public function payment() {
|
|
|
|
return $this->belongsTo(Payment::class);
|
|
|
|
}
|
2021-07-23 07:25:26 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
2018-05-20 12:53:14 +00:00
|
|
|
}
|