mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 13:42:49 +01:00
Fix for applying multiple credits
This commit is contained in:
parent
ce899cfe4d
commit
6c9c892d7c
@ -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…
Reference in New Issue
Block a user