Optimise product tables
This commit is contained in:
@@ -26,11 +26,9 @@ class Payment extends Model implements IDs
|
||||
{
|
||||
use PushNew;
|
||||
|
||||
const CREATED_AT = 'date_orig';
|
||||
const UPDATED_AT = 'date_last';
|
||||
|
||||
protected $dates = ['payment_date'];
|
||||
protected $dateFormat = 'U';
|
||||
protected $dates = [
|
||||
'paid_at',
|
||||
];
|
||||
|
||||
// Array of items that can be updated with PushNew
|
||||
protected $pushable = ['items'];
|
||||
@@ -75,7 +73,7 @@ class Payment extends Model implements IDs
|
||||
public function scopeUnapplied($query)
|
||||
{
|
||||
return $query
|
||||
->select(['payments.id','payment_date','account_id','checkout_id','total_amt',DB::raw("SUM(alloc_amt) as allocated")])
|
||||
->select(['payments.id','payment_date','account_id','checkout_id','total_amt',DB::raw("SUM(amount) as allocated")])
|
||||
->leftJoin('payment_items',['payment_items.payment_id'=>'payments.id'])
|
||||
->groupBy(['payments.id','payment_date','total_amt','account_id','checkout_id'])
|
||||
->having(DB::raw('ROUND(total_amt-IFNULL(allocated,0),2)'),'>',self::threshold);
|
||||
@@ -85,7 +83,7 @@ class Payment extends Model implements IDs
|
||||
|
||||
public function getBalanceAttribute(): float
|
||||
{
|
||||
$balance = $this->getTotalAttribute()-$this->items->sum('alloc_amt');
|
||||
$balance = $this->getTotalAttribute()-$this->items->sum('amount');
|
||||
|
||||
return ($balance < self::threshold) ? 0 : $balance;
|
||||
}
|
||||
|
Reference in New Issue
Block a user