Add paypal payments
This commit is contained in:
@@ -13,4 +13,31 @@ class Checkout extends Model
|
||||
{
|
||||
return $this->hasMany(Payment::class);
|
||||
}
|
||||
|
||||
/** SCOPES **/
|
||||
|
||||
/**
|
||||
* Search for a record
|
||||
*
|
||||
* @param $query
|
||||
* @param string $term
|
||||
* @return
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('active',TRUE);
|
||||
}
|
||||
|
||||
/** FUNCTIONS **/
|
||||
|
||||
public function fee(float $amt,int $items=1): float
|
||||
{
|
||||
if (! $this->fee_passon OR ! $items)
|
||||
return 0;
|
||||
|
||||
$fee = $amt+$this->fee_fixed/$items;
|
||||
$fee /= (1-$this->fee_variable);
|
||||
|
||||
return round($fee-$amt,2);
|
||||
}
|
||||
}
|
@@ -94,7 +94,18 @@ class Invoice extends Model
|
||||
|
||||
public function getPaidAttribute()
|
||||
{
|
||||
return $this->currency()->round($this->paymentitems->sum('alloc_amt'));
|
||||
return $this->currency()->round(
|
||||
$this->paymentitems
|
||||
->filter(function($item) { return ! $item->payment->pending_status; })
|
||||
->sum('alloc_amt'));
|
||||
}
|
||||
|
||||
public function getPendingPaidAttribute()
|
||||
{
|
||||
return $this->currency()->round(
|
||||
$this->paymentitems
|
||||
->filter(function($item) { return $item->payment->pending_status; })
|
||||
->sum('alloc_amt'));
|
||||
}
|
||||
|
||||
public function getSubTotalAttribute()
|
||||
|
@@ -4,11 +4,12 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Traits\PushNew;
|
||||
use App\Traits\NextKey;
|
||||
|
||||
class Payment extends Model
|
||||
{
|
||||
use NextKey;
|
||||
use NextKey,PushNew;
|
||||
const RECORD_ID = 'payment';
|
||||
public $incrementing = FALSE;
|
||||
|
||||
@@ -20,6 +21,9 @@ class Payment extends Model
|
||||
protected $dateFormat = 'U';
|
||||
protected $with = ['account.country.currency','items'];
|
||||
|
||||
// Array of items that can be updated with PushNew
|
||||
protected $pushable = ['items'];
|
||||
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo(Account::class);
|
||||
|
@@ -4,7 +4,21 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Traits\NextKey;
|
||||
use App\Traits\PushNew;
|
||||
|
||||
class PaymentItem extends Model
|
||||
{
|
||||
use NextKey,PushNew;
|
||||
const RECORD_ID = 'payment_item';
|
||||
public $incrementing = FALSE;
|
||||
|
||||
const CREATED_AT = 'date_orig';
|
||||
const UPDATED_AT = 'date_last';
|
||||
|
||||
protected $table = 'ab_payment_item';
|
||||
|
||||
public function payment() {
|
||||
return $this->belongsTo(Payment::class);
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
Reference in New Issue
Block a user