mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04: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;
|
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);
|
$paymentDriver = $account->paymentDriver($invitation, GATEWAY_TYPE_TOKEN);
|
||||||
$customer = $paymentDriver->customer();
|
$customer = $paymentDriver->customer();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user