mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Fixes for payments (#3271)
* Fixes + tests for unapplied amounts not adjusting when updating a payment * fixes for payment amounts check
This commit is contained in:
parent
c3da9c80b3
commit
cdf22f6a1f
@ -16,7 +16,7 @@ use App\Models\User;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
/**
|
||||
* Class NewUniqueUserRule
|
||||
* Class PaymentAmountsBalanceRule
|
||||
* @package App\Http\ValidationRules
|
||||
*/
|
||||
class PaymentAmountsBalanceRule implements Rule
|
||||
@ -42,6 +42,17 @@ class PaymentAmountsBalanceRule implements Rule
|
||||
|
||||
private function calculateAmounts() :bool
|
||||
{
|
||||
/**
|
||||
* Sometimes the request may not contain the amount or it may be zero,
|
||||
* and this is a valid use case, only compare the amounts if they
|
||||
* have been presented!
|
||||
*/
|
||||
|
||||
if(!request()->has('amount'))
|
||||
return true;
|
||||
|
||||
if(request()->has('amount') && request()->input('amount') == 0)
|
||||
return true
|
||||
|
||||
$payment_amounts = 0;
|
||||
$invoice_amounts = 0;
|
||||
|
@ -69,8 +69,8 @@ class PaymentRepository extends BaseRepository
|
||||
private function applyPayment(array $data, Payment $payment): ?Payment
|
||||
{
|
||||
|
||||
|
||||
$payment->fill($data);
|
||||
|
||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
|
||||
$payment->save();
|
||||
@ -127,9 +127,9 @@ class PaymentRepository extends BaseRepository
|
||||
$invoice_totals -= $credit_totals;
|
||||
|
||||
if ($invoice_totals == $payment->amount)
|
||||
$payment->applied = $payment->amount;
|
||||
$payment->applied += $payment->amount;
|
||||
elseif ($invoice_totals < $payment->amount)
|
||||
$payment->applied = $invoice_totals;
|
||||
$payment->applied += $invoice_totals;
|
||||
|
||||
//UpdateInvoicePayment::dispatchNow($payment);
|
||||
$payment->save();
|
||||
|
@ -945,7 +945,11 @@ class PaymentTest extends TestCase
|
||||
}
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals(20, $arr['data']['applied']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user