2018-08-01 07:09:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2021-10-01 04:59:04 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2018-08-01 07:09:38 +00:00
|
|
|
|
2021-10-01 04:59:04 +00:00
|
|
|
/**
|
|
|
|
* CLEANUP NOTES:
|
|
|
|
* + Charge Date should not be null
|
|
|
|
* + Attributes should be a collection array
|
|
|
|
* + type should not be null
|
|
|
|
*/
|
2018-08-01 07:09:38 +00:00
|
|
|
class Charge extends Model
|
|
|
|
{
|
2021-10-01 04:59:04 +00:00
|
|
|
const CREATED_AT = 'date_orig';
|
|
|
|
const UPDATED_AT = 'date_last';
|
|
|
|
|
|
|
|
protected $dates = ['charge_date'];
|
2019-07-04 04:55:05 +00:00
|
|
|
public $dateFormat = 'U';
|
2018-08-01 07:09:38 +00:00
|
|
|
|
2021-10-01 04:59:04 +00:00
|
|
|
public const sweep = [
|
|
|
|
// 0 => 'Daily',
|
|
|
|
// 1 => 'Weekly',
|
|
|
|
// 2 => 'Monthly',
|
|
|
|
// 3 => 'Quarterly',
|
|
|
|
// 4 => 'Semi-Annually',
|
|
|
|
// 5 => 'Annually',
|
|
|
|
6 => 'Service Rebill',
|
|
|
|
];
|
|
|
|
|
|
|
|
/* RELATIONS */
|
|
|
|
|
|
|
|
public function account()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Account::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function service()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Service::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SCOPES */
|
|
|
|
|
|
|
|
public function scopeUnprocessed($query)
|
|
|
|
{
|
|
|
|
return $query
|
|
|
|
->where('active',TRUE)
|
|
|
|
->whereNotNull('charge_date')
|
|
|
|
->whereNotNull('type')
|
|
|
|
->where(function($q) {
|
|
|
|
return $q->where('processed',FALSE)
|
|
|
|
->orWhereNull('processed');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ATTRIBUTES */
|
|
|
|
|
2018-08-01 07:09:38 +00:00
|
|
|
public function getNameAttribute()
|
|
|
|
{
|
2021-07-19 06:23:38 +00:00
|
|
|
return sprintf('%s %s',$this->description,$this->getAttribute('attributes') ? join('|',unserialize($this->getAttribute('attributes'))) : '');
|
2018-08-01 07:09:38 +00:00
|
|
|
}
|
2021-10-01 04:59:04 +00:00
|
|
|
|
2021-12-16 00:55:59 +00:00
|
|
|
public function getTypeNameAttribute(): string
|
2021-10-01 04:59:04 +00:00
|
|
|
{
|
2021-12-16 00:55:59 +00:00
|
|
|
return Arr::get(InvoiceItem::type,$this->attribute('type'));
|
2021-10-01 04:59:04 +00:00
|
|
|
}
|
2018-08-01 07:09:38 +00:00
|
|
|
}
|