mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 15:34:35 -04:00
Fixes for payment tests
This commit is contained in:
parent
eeb87dc5cb
commit
d919134bb9
@ -36,7 +36,7 @@ class UpdatePaymentRequest extends Request
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'invoices' => ['array', new PaymentAppliedValidAmount, new ValidCreditsPresentRule($this->all())],
|
'invoices' => ['array', new PaymentAppliedValidAmount($this->all()), new ValidCreditsPresentRule($this->all())],
|
||||||
'invoices.*.invoice_id' => 'distinct',
|
'invoices.*.invoice_id' => 'distinct',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -87,6 +87,7 @@ class UpdatePaymentRequest extends Request
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->replace($input);
|
$this->replace($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,10 @@ class PaymentAppliedValidAmount implements Rule
|
|||||||
|
|
||||||
private $message;
|
private $message;
|
||||||
|
|
||||||
|
public function __construct(private array $input)
|
||||||
|
{
|
||||||
|
$this->input = $input;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @param string $attribute
|
* @param string $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
@ -48,7 +52,7 @@ class PaymentAppliedValidAmount implements Rule
|
|||||||
private function calculateAmounts() :bool
|
private function calculateAmounts() :bool
|
||||||
{
|
{
|
||||||
$payment = Payment::withTrashed()->whereId($this->decodePrimaryKey(request()->segment(4)))->company()->first();
|
$payment = Payment::withTrashed()->whereId($this->decodePrimaryKey(request()->segment(4)))->company()->first();
|
||||||
$inv_collection = Invoice::withTrashed()->whereIn('id', array_column(request()->input('invoices'), 'invoice_id'))->get();
|
$inv_collection = Invoice::withTrashed()->whereIn('id', array_column($this->input['invoices'], 'invoice_id'))->get();
|
||||||
|
|
||||||
if (! $payment) {
|
if (! $payment) {
|
||||||
return false;
|
return false;
|
||||||
@ -74,15 +78,15 @@ class PaymentAppliedValidAmount implements Rule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request()->input('invoices') && is_array(request()->input('invoices'))) {
|
if (isset($this->input['invoices']) && is_array($this->input['invoices'])) {
|
||||||
foreach (request()->input('invoices') as $invoice) {
|
foreach ($this->input['invoices'] as $invoice) {
|
||||||
$invoice_amounts += $invoice['amount'];
|
$invoice_amounts += $invoice['amount'];
|
||||||
|
|
||||||
$inv = $inv_collection->firstWhere('id', $invoice['invoice_id']);
|
$inv = $inv_collection->firstWhere('id', $invoice['invoice_id']);
|
||||||
|
nlog($inv);
|
||||||
|
|
||||||
if($inv->balance < $invoice['amount']) {
|
if($inv->balance < $invoice['amount']) {
|
||||||
|
|
||||||
// $this->message = ctrans('texts.insufficient_applied_amount_remaining');
|
|
||||||
$this->message = 'Amount cannot be greater than invoice balance';
|
$this->message = 'Amount cannot be greater than invoice balance';
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user