mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Use credits for payments in client portal
This commit is contained in:
parent
b7292a0432
commit
57faf6eeb5
@ -155,27 +155,16 @@ class PaymentController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
//$payment_methods = auth()->user()->client->getPaymentMethods(array_sum(array_column($payable_invoices, 'amount_with_fee')));
|
||||
|
||||
$payment_method_id = request()->input('payment_method_id');
|
||||
|
||||
$invoice_totals = array_sum(array_column($payable_invoices, 'amount'));
|
||||
|
||||
$first_invoice = $invoices->first();
|
||||
|
||||
$credit_totals = $first_invoice->client->service()->getCreditBalance();
|
||||
|
||||
$starting_invoice_amount = $first_invoice->amount;
|
||||
|
||||
// $fee_totals = round($gateway->calcGatewayFee($invoice_totals, true), $first_invoice->client->currency()->precision);
|
||||
|
||||
// if (!$first_invoice->uses_inclusive_taxes) {
|
||||
// $fee_tax = 0;
|
||||
// $fee_tax += round(($first_invoice->tax_rate1 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
|
||||
// $fee_tax += round(($first_invoice->tax_rate2 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
|
||||
// $fee_tax += round(($first_invoice->tax_rate3 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
|
||||
|
||||
// $fee_totals += $fee_tax;
|
||||
// }
|
||||
|
||||
$first_invoice->service()->addGatewayFee($gateway, $payment_method_id, $invoice_totals)->save();
|
||||
|
||||
/**
|
||||
@ -194,9 +183,10 @@ class PaymentController extends Controller
|
||||
$payment_hash->save();
|
||||
|
||||
$totals = [
|
||||
'credit_totals' => $credit_totals,
|
||||
'invoice_totals' => $invoice_totals,
|
||||
'fee_total' => $fee_totals,
|
||||
'amount_with_fee' => $invoice_totals + $fee_totals,
|
||||
'amount_with_fee' => max(0, (($invoice_totals + $fee_totals) - $credit_totals)),
|
||||
];
|
||||
|
||||
$data = [
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace App\Services\Client;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Utils\Number;
|
||||
|
||||
class ClientService
|
||||
{
|
||||
@ -43,6 +44,16 @@ class ClientService
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreditBalance() :float
|
||||
{
|
||||
$credits = $this->client->credits
|
||||
->where('is_deleted', false)
|
||||
->where('balance', '>', 0)
|
||||
->sortBy('created_at');
|
||||
|
||||
return Number::roundValue($credits->sum('balance'), $this->client->currency()->precision);
|
||||
}
|
||||
|
||||
public function save() :Client
|
||||
{
|
||||
$this->client->save();
|
||||
|
@ -38,7 +38,12 @@
|
||||
<li class="list-group-item d-flex list-group-item-action justify-content-between align-items-center"><strong>{{ ctrans('texts.total')}}</strong>
|
||||
<h3><span class="badge badge-primary badge-pill"><strong>{{ $amount }}</strong></span></h3>
|
||||
</li>
|
||||
@if($fee)
|
||||
@if($credit_totals > 0)
|
||||
<li class="list-group-item d-flex list-group-item-action justify-content-between align-items-center"><strong>{{ ctrans('texts.credit_amount')}}</strong>
|
||||
<h3><span class="badge badge-primary badge-pill"><strong>{{ $credit_totals }}</strong></span></h3>
|
||||
</li>
|
||||
@endifs
|
||||
@if($fee > 0)
|
||||
<li class="list-group-item d-flex list-group-item-action justify-content-between align-items-center"><strong>{{ ctrans('texts.gateway_fee')}}</strong>
|
||||
<h3><span class="badge badge-primary badge-pill"><strong>{{ $fee }}</strong></span></h3>
|
||||
</li>
|
||||
|
@ -39,21 +39,33 @@
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ App\Utils\Number::formatMoney($total['invoice_totals'], $client) }}
|
||||
</dd>
|
||||
@if($total['fee_total'] > 0)
|
||||
<dt class="text-sm leading-5 font-medium text-gray-500">
|
||||
{{ ctrans('texts.gateway_fees') }}
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ App\Utils\Number::formatMoney($total['fee_total'], $client) }}
|
||||
</dd>
|
||||
@endif
|
||||
@if($total['credit_totals'] > 0)
|
||||
<dt class="text-sm leading-5 font-medium text-gray-500">
|
||||
{{ ctrans('texts.total') }}
|
||||
{{ ctrans('texts.credit_amount') }}
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ App\Utils\Number::formatMoney($total['credit_totals'], $client) }}
|
||||
</dd>
|
||||
@endif
|
||||
<dt class="text-sm leading-5 font-medium text-gray-500">
|
||||
{{ ctrans('texts.amount_due') }}
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ App\Utils\Number::formatMoney($total['amount_with_fee'], $client) }}
|
||||
</dd>
|
||||
</div>
|
||||
|
||||
@if($token)
|
||||
@if((int)$total['amount_with_fee'] == 0)
|
||||
<!-- finalize with credits only -->
|
||||
<button class="button button-primary bg-primary inline-flex items-center">Pay with credit</button>
|
||||
@elseif($token)
|
||||
<div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6 flex items-center">
|
||||
<dt class="text-sm leading-5 font-medium text-gray-500 mr-4">
|
||||
{{ ctrans('texts.credit_card') }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user