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:
parent
5adc665a95
commit
9d4c6a12dd
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user