mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 06:14:35 -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');
|
$payment_method_id = request()->input('payment_method_id');
|
||||||
|
|
||||||
$invoice_totals = array_sum(array_column($payable_invoices, 'amount'));
|
$invoice_totals = array_sum(array_column($payable_invoices, 'amount'));
|
||||||
|
|
||||||
$first_invoice = $invoices->first();
|
$first_invoice = $invoices->first();
|
||||||
|
|
||||||
|
$credit_totals = $first_invoice->client->service()->getCreditBalance();
|
||||||
|
|
||||||
$starting_invoice_amount = $first_invoice->amount;
|
$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();
|
$first_invoice->service()->addGatewayFee($gateway, $payment_method_id, $invoice_totals)->save();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -194,9 +183,10 @@ class PaymentController extends Controller
|
|||||||
$payment_hash->save();
|
$payment_hash->save();
|
||||||
|
|
||||||
$totals = [
|
$totals = [
|
||||||
|
'credit_totals' => $credit_totals,
|
||||||
'invoice_totals' => $invoice_totals,
|
'invoice_totals' => $invoice_totals,
|
||||||
'fee_total' => $fee_totals,
|
'fee_total' => $fee_totals,
|
||||||
'amount_with_fee' => $invoice_totals + $fee_totals,
|
'amount_with_fee' => max(0, (($invoice_totals + $fee_totals) - $credit_totals)),
|
||||||
];
|
];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Services\Client;
|
namespace App\Services\Client;
|
||||||
|
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
|
use App\Utils\Number;
|
||||||
|
|
||||||
class ClientService
|
class ClientService
|
||||||
{
|
{
|
||||||
@ -43,6 +44,16 @@ class ClientService
|
|||||||
return $this;
|
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
|
public function save() :Client
|
||||||
{
|
{
|
||||||
$this->client->save();
|
$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>
|
<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>
|
<h3><span class="badge badge-primary badge-pill"><strong>{{ $amount }}</strong></span></h3>
|
||||||
</li>
|
</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>
|
<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>
|
<h3><span class="badge badge-primary badge-pill"><strong>{{ $fee }}</strong></span></h3>
|
||||||
</li>
|
</li>
|
||||||
|
@ -39,21 +39,33 @@
|
|||||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
<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) }}
|
{{ App\Utils\Number::formatMoney($total['invoice_totals'], $client) }}
|
||||||
</dd>
|
</dd>
|
||||||
|
@if($total['fee_total'] > 0)
|
||||||
<dt class="text-sm leading-5 font-medium text-gray-500">
|
<dt class="text-sm leading-5 font-medium text-gray-500">
|
||||||
{{ ctrans('texts.gateway_fees') }}
|
{{ ctrans('texts.gateway_fees') }}
|
||||||
</dt>
|
</dt>
|
||||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
<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) }}
|
{{ App\Utils\Number::formatMoney($total['fee_total'], $client) }}
|
||||||
</dd>
|
</dd>
|
||||||
|
@endif
|
||||||
|
@if($total['credit_totals'] > 0)
|
||||||
<dt class="text-sm leading-5 font-medium text-gray-500">
|
<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>
|
</dt>
|
||||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
<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) }}
|
{{ App\Utils\Number::formatMoney($total['amount_with_fee'], $client) }}
|
||||||
</dd>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
|
@if((int)$total['amount_with_fee'] == 0)
|
||||||
@if($token)
|
<!-- 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">
|
<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">
|
<dt class="text-sm leading-5 font-medium text-gray-500 mr-4">
|
||||||
{{ ctrans('texts.credit_card') }}
|
{{ ctrans('texts.credit_card') }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user