2018-05-20 12:53:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
2021-06-29 06:36:34 +00:00
|
|
|
use App\Interfaces\IDs;
|
|
|
|
use App\Traits\{NextKey,PushNew};
|
2019-06-07 06:54:27 +00:00
|
|
|
|
2021-06-29 06:36:34 +00:00
|
|
|
/**
|
|
|
|
* Class Payment
|
|
|
|
* Payments that belong to an account
|
|
|
|
*
|
|
|
|
* Attributes for payments:
|
|
|
|
* + lid : Local ID for payment
|
|
|
|
* + payment_date : Date payment received
|
|
|
|
* + sid : System ID for payment
|
|
|
|
* + total : Payment total
|
|
|
|
*
|
|
|
|
* @package App\Models
|
|
|
|
*/
|
|
|
|
class Payment extends Model implements IDs
|
2018-05-20 12:53:14 +00:00
|
|
|
{
|
2020-07-27 04:49:59 +00:00
|
|
|
use NextKey,PushNew;
|
2021-06-29 06:36:34 +00:00
|
|
|
|
2020-02-09 12:12:34 +00:00
|
|
|
const RECORD_ID = 'payment';
|
|
|
|
public $incrementing = FALSE;
|
2019-06-07 06:54:27 +00:00
|
|
|
|
|
|
|
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'];
|
2019-06-07 06:54:27 +00:00
|
|
|
protected $dateFormat = 'U';
|
2021-07-02 04:35:43 +00:00
|
|
|
//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'];
|
|
|
|
|
2021-06-29 06:36:34 +00:00
|
|
|
/* RELATIONS */
|
|
|
|
|
2018-06-19 12:31:49 +00:00
|
|
|
public function account()
|
|
|
|
{
|
2018-07-13 04:53:44 +00:00
|
|
|
return $this->belongsTo(Account::class);
|
2018-06-19 12:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function items()
|
|
|
|
{
|
|
|
|
return $this->hasMany(PaymentItem::class);
|
|
|
|
}
|
|
|
|
|
2021-06-29 06:36:34 +00:00
|
|
|
/* ATTRIBUTES */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
* @deprecated use date_payment directly.
|
|
|
|
*/
|
2018-06-19 12:31:49 +00:00
|
|
|
public function getDatePaidAttribute()
|
2018-05-20 12:53:14 +00:00
|
|
|
{
|
|
|
|
return $this->date_payment->format('Y-m-d');
|
|
|
|
}
|
2018-06-19 12:31:49 +00:00
|
|
|
|
2021-06-29 06:36:34 +00:00
|
|
|
/**
|
|
|
|
* Payment Local ID
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLIDattribute(): string
|
|
|
|
{
|
|
|
|
return sprintf('%06s',$this->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Payment System ID
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSIDAttribute(): string
|
|
|
|
{
|
|
|
|
return sprintf('%02s-%04s#%s',$this->site_id,$this->account_id,$this->getLIDattribute());
|
|
|
|
}
|
|
|
|
|
2018-06-19 12:31:49 +00:00
|
|
|
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
|
|
|
}
|