1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Fix for applying multiple credits

This commit is contained in:
Hillel Coren 2016-08-09 09:39:20 +03:00
parent e85517c4a8
commit e36db657cc

View File

@ -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;
}
}