Payments need to be active to be recognised

This commit is contained in:
Deon George 2022-06-13 17:24:43 +10:00
parent 28438c6423
commit 5e82f091c0
7 changed files with 9 additions and 5 deletions

View File

@ -116,6 +116,7 @@ class AdminController extends Controller
if (! $o->exists) { if (! $o->exists) {
$o->forceFill($request->only(['account_id','paid_at','checkout_id','checkout_id','total_amt','fees_amt','source_id','pending','notes','ip'])); $o->forceFill($request->only(['account_id','paid_at','checkout_id','checkout_id','total_amt','fees_amt','source_id','pending','notes','ip']));
$o->site_id = config('site')->site_id; $o->site_id = config('site')->site_id;
$o->active = TRUE;
$o->save(); $o->save();
} }

View File

@ -200,6 +200,7 @@ class PaypalController extends Controller
foreach ($response->result->purchase_units as $pu) { foreach ($response->result->purchase_units as $pu) {
foreach ($pu->payments->captures as $cap) { foreach ($pu->payments->captures as $cap) {
$po = new Payment; $po = new Payment;
$po->active = TRUE;
switch ($cap->status) { switch ($cap->status) {
case 'PENDING': case 'PENDING':

View File

@ -88,6 +88,7 @@ final class PaymentsImport implements ShouldQueue
// New Payment // New Payment
$po = new Payment; $po = new Payment;
$po->active = TRUE;
$po->site_id = 1; // @todo $po->site_id = 1; // @todo
$po->paid_at = $pd; $po->paid_at = $pd;
$po->checkout_id = '999'; // @todo $po->checkout_id = '999'; // @todo

View File

@ -195,7 +195,8 @@ class Invoice extends Model implements IDs
public function payments() public function payments()
{ {
return $this->hasManyThrough(Payment::class,PaymentItem::class,NULL,'id',NULL,'payment_id'); return $this->hasManyThrough(Payment::class,PaymentItem::class,NULL,'id',NULL,'payment_id')
->active();
} }
public function paymentitems() public function paymentitems()
@ -262,7 +263,7 @@ class Invoice extends Model implements IDs
public function getPaidAttribute(): float public function getPaidAttribute(): float
{ {
return $this->paymentitems return $this->paymentitems
->filter(function($item) { return ! $item->payment->pending_status; }) ->filter(function($item) { return ! $item->payment->pending_status && $item->payment->active; })
->sum('amount'); ->sum('amount');
} }

View File

@ -24,7 +24,7 @@ use App\Traits\PushNew;
*/ */
class Payment extends Model implements IDs class Payment extends Model implements IDs
{ {
use PushNew; use PushNew,ScopeActive;
protected $dates = [ protected $dates = [
'paid_at', 'paid_at',

View File

@ -32,7 +32,7 @@
</thead> </thead>
<tbody> <tbody>
@foreach(\App\Models\Payment::unapplied()->with(['account.user','checkout','items'])->get() as $o) @foreach(\App\Models\Payment::active()->unapplied()->with(['account.user','checkout','items'])->get() as $o)
@if (! $o->balance) @continue @endif @if (! $o->balance) @continue @endif
<tr> <tr>
<td><a href="{{ url('a/payment/addedit',$o->id) }}">{{ $o->id }}</td> <td><a href="{{ url('a/payment/addedit',$o->id) }}">{{ $o->id }}</td>

View File

@ -5,7 +5,7 @@
</div> </div>
<div class="card-body"> <div class="card-body">
@if(($x=$o->payments()->where('payments.created_at','>',\Carbon\Carbon::now()->subMonths(12)->unix())->with(['items','account'])->get())->count()) @if(($x=$o->payments()->active()->where('payments.created_at','>',\Carbon\Carbon::now()->subMonths(12)->unix())->with(['items','account'])->get())->count())
<table class="table table-bordered w-100" id="payments_past"> <table class="table table-bordered w-100" id="payments_past">
<thead> <thead>
<tr> <tr>