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

Use credits when autobilling invoices

This commit is contained in:
Hillel Coren 2016-07-19 20:12:28 +03:00
parent 5adc665a95
commit 9d4c6a12dd

View File

@ -57,6 +57,21 @@ class PaymentService extends BaseService
return false;
}
if ($credits = $client->credits->sum('balance')) {
$balance = $invoice->balance;
$amount = min($credits, $balance);
$data = [
'payment_type_id' => PAYMENT_TYPE_CREDIT,
'invoice_id' => $invoice->id,
'client_id' => $client->id,
'amount' => $amount,
];
$payment = $this->paymentRepo->save($data);
if ($amount == $balance) {
return $payment;
}
}
$paymentDriver = $account->paymentDriver($invitation, GATEWAY_TYPE_TOKEN);
$customer = $paymentDriver->customer();