Handle edge case when deleting/restoring invoices

This commit is contained in:
David Bomba 2023-07-12 09:04:27 +10:00
parent 8e12cfe4d5
commit f009f08171

View File

@ -44,6 +44,7 @@ class HandleRestore extends AbstractService
//cannot restore an invoice with a deleted payment //cannot restore an invoice with a deleted payment
foreach ($this->invoice->payments as $payment) { foreach ($this->invoice->payments as $payment) {
if (($this->invoice->paid_to_date == 0) && $payment->is_deleted) { if (($this->invoice->paid_to_date == 0) && $payment->is_deleted) {
$this->invoice->delete(); //set it back to deleted so that it can be restored from repository
return $this->invoice; return $this->invoice;
} }
} }