Fix for applying multiple credits
This commit is contained in:
parent
e85517c4a8
commit
e36db657cc
1 changed files with 3 additions and 4 deletions
|
|
@ -180,12 +180,11 @@ class PaymentRepository extends BaseRepository
|
|||
if ($paymentTypeId == PAYMENT_TYPE_CREDIT) {
|
||||
$credits = Credit::scope()->where('client_id', '=', $clientId)
|
||||
->where('balance', '>', 0)->orderBy('created_at')->get();
|
||||
$applied = 0;
|
||||
|
||||
$remaining = $amount;
|
||||
foreach ($credits as $credit) {
|
||||
$applied += $credit->apply($amount);
|
||||
|
||||
if ($applied >= $amount) {
|
||||
$remaining -= $credit->apply($remaining);
|
||||
if ( ! $remaining) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue