Fixes for auto-archive invoices

This commit is contained in:
David Bomba 2021-08-08 08:40:04 +10:00
parent 659b955862
commit d29f1798a2
4 changed files with 18 additions and 7 deletions

View File

@ -126,7 +126,7 @@ class ApplyPayment extends AbstractService
});
$this->invoice->service()->applyNumber()->save();
$this->invoice->service()->applyNumber()->workFlow()->save();
return $this->invoice;
}

View File

@ -20,6 +20,7 @@ use App\Models\Expense;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Task;
use App\Repositories\BaseRepository;
use App\Services\Client\ClientService;
use App\Services\Invoice\UpdateReminder;
use App\Utils\Ninja;
@ -271,9 +272,8 @@ class InvoiceService
{
if ((int)$this->invoice->balance == 0) {
InvoiceWorkflowSettings::dispatchNow($this->invoice);
$this->setStatus(Invoice::STATUS_PAID);
$this->setStatus(Invoice::STATUS_PAID)->workFlow();
// InvoiceWorkflowSettings::dispatchNow($this->invoice);
}
if ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) {
@ -449,6 +449,18 @@ class InvoiceService
return $this;
}
public function workFlow()
{
if ($this->invoice->status_id == Invoice::STATUS_PAID && $this->invoice->client->getSetting('auto_archive_invoice')) {
/* Throws: Payment amount xxx does not match invoice totals. */
$base_repository = new BaseRepository();
$base_repository->archive($this->invoice);
}
return $this;
}
/**
* Saves the invoice.
* @return Invoice object

View File

@ -95,7 +95,8 @@ class MarkPaid extends AbstractService
->updatePaidToDate($payment->amount)
->save();
InvoiceWorkflowSettings::dispatchNow($this->invoice);
$this->invoice->service()->workFlow()->save();
// InvoiceWorkflowSettings::dispatchNow($this->invoice);
return $this->invoice;
}

View File

@ -85,8 +85,6 @@ class UpdateInvoicePayment
->deletePdf()
->save();
InvoiceWorkflowSettings::dispatchNow($invoice);
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
});