mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Add rules preventing overpayment on invoices
This commit is contained in:
parent
79723759eb
commit
db9e8ff830
@ -53,21 +53,40 @@ class ValidInvoicesRules implements Rule
|
||||
|
||||
//todo optimize this into a single query
|
||||
foreach ($this->input['invoices'] as $invoice) {
|
||||
|
||||
$unique_array[] = $invoice['invoice_id'];
|
||||
|
||||
$inv = Invoice::whereId($invoice['invoice_id'])->first();
|
||||
|
||||
if (! $inv) {
|
||||
|
||||
$this->error_msg = 'Invoice not found ';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($inv->client_id != $this->input['client_id']) {
|
||||
|
||||
$this->error_msg = 'Selected invoices are not from a single client';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if($inv->status_id == Invoice::STATUS_DRAFT && $invoice['amount'] == $inv->amount){
|
||||
//catch here nothing to do - we need this to prevent the last elseif triggering
|
||||
}
|
||||
else if($inv->status_id == Invoice::STATUS_DRAFT && $invoice['amount'] > $inv->amount){
|
||||
|
||||
$this->error_msg = 'Amount cannot be greater than invoice balance';
|
||||
|
||||
return false;
|
||||
}
|
||||
else if($invoice['amount'] > $inv->balance) {
|
||||
|
||||
$this->error_msg = 'Amount cannot be greater than invoice balance';
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (! (array_unique($unique_array) == $unique_array)) {
|
||||
|
@ -100,11 +100,6 @@ class ApplyPayment extends AbstractService
|
||||
}
|
||||
}
|
||||
|
||||
// $this->payment
|
||||
// ->ledger()
|
||||
// ->updatePaymentBalance($this->payment_amount * -1);
|
||||
|
||||
|
||||
$this->payment
|
||||
->ledger()
|
||||
->updatePaymentBalance($amount_paid);
|
||||
|
Loading…
x
Reference in New Issue
Block a user