Optimise charge table, implemented charge recording, optimised payment recording
This commit is contained in:
@@ -3,15 +3,67 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/**
|
||||
* CLEANUP NOTES:
|
||||
* + Charge Date should not be null
|
||||
* + Attributes should be a collection array
|
||||
* + type should not be null
|
||||
*/
|
||||
class Charge extends Model
|
||||
{
|
||||
protected $table = 'ab_charge';
|
||||
protected $dates = ['date_charge'];
|
||||
const CREATED_AT = 'date_orig';
|
||||
const UPDATED_AT = 'date_last';
|
||||
|
||||
protected $dates = ['charge_date'];
|
||||
public $dateFormat = 'U';
|
||||
|
||||
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 */
|
||||
|
||||
public function getNameAttribute()
|
||||
{
|
||||
return sprintf('%s %s',$this->description,$this->getAttribute('attributes') ? join('|',unserialize($this->getAttribute('attributes'))) : '');
|
||||
}
|
||||
|
||||
public function getTypeAttribute($value)
|
||||
{
|
||||
return Arr::get(InvoiceItem::type,$value);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user