1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 09:21:34 +02:00

Fix for applying multiple credits

This commit is contained in:
Hillel Coren 2016-08-09 09:39:37 +03:00
parent ce899cfe4d
commit 6c9c892d7c

View File

@ -180,12 +180,11 @@ class PaymentRepository extends BaseRepository
if ($paymentTypeId == PAYMENT_TYPE_CREDIT) { if ($paymentTypeId == PAYMENT_TYPE_CREDIT) {
$credits = Credit::scope()->where('client_id', '=', $clientId) $credits = Credit::scope()->where('client_id', '=', $clientId)
->where('balance', '>', 0)->orderBy('created_at')->get(); ->where('balance', '>', 0)->orderBy('created_at')->get();
$applied = 0;
$remaining = $amount;
foreach ($credits as $credit) { foreach ($credits as $credit) {
$applied += $credit->apply($amount); $remaining -= $credit->apply($remaining);
if ( ! $remaining) {
if ($applied >= $amount) {
break; break;
} }
} }