diff --git a/app/Http/ValidationRules/Invoice/InvoiceBalanceSanity.php b/app/Http/ValidationRules/Invoice/InvoiceBalanceSanity.php index e171667b44..be3d16dc2a 100644 --- a/app/Http/ValidationRules/Invoice/InvoiceBalanceSanity.php +++ b/app/Http/ValidationRules/Invoice/InvoiceBalanceSanity.php @@ -57,13 +57,13 @@ class InvoiceBalanceSanity implements Rule private function checkIfInvoiceBalanceIsSane() : bool { - $this->invoice->line_items = $this->input['line_items']; + DB::connection(config('database.default'))->beginTransaction(); - DB::beginTransaction(); + $this->invoice = Invoice::on(config('database.default'))->find($this->invoice->id); + $this->invoice->line_items = $this->input['line_items']; + $temp_invoice = $this->invoice->calc()->getTempEntity(); - $temp_invoice = $this->invoice->calc()->getTempEntity(); - - DB::rollBack(); + DB::connection(config('database.default'))->rollBack(); if($temp_invoice->balance < 0){ $this->message = 'Invoice balance cannot go negative'; @@ -71,7 +71,7 @@ class InvoiceBalanceSanity implements Rule } - return true; + return true; } } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index bfe250ea26..578cf0741b 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -305,6 +305,10 @@ class BaseRepository /* Perform model specific tasks */ if ($model instanceof Invoice) { + + nlog("Finished amount = " . $state['finished_amount']); + nlog("Starting amount = " . $state['starting_amount']); + nlog("Diff = " . ($state['finished_amount'] - $state['starting_amount'])); if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) {