diff --git a/app/Models/Company.php b/app/Models/Company.php index 006a09b0..2a3b2908 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -300,6 +300,10 @@ class Company extends Model implements HasMedia if ($this->invoices()->exists()) { $this->invoices->map(function ($invoice) { $this->checkModelData($invoice); + + if ($invoice->transactions()->exists()) { + $invoice->transactions()->delete(); + } }); $this->invoices()->delete(); diff --git a/app/Models/Customer.php b/app/Models/Customer.php index f5a5a104..8b6a5af6 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -139,7 +139,12 @@ class Customer extends Authenticatable implements HasMedia } if ($customer->invoices()->exists()) { - $customer->invoices()->delete(); + $customer->invoices->map(function ($invoice) { + if ($invoice->transactions()->exists()) { + $invoice->transactions()->delete(); + } + $invoice->delete(); + }); } if ($customer->payments()->exists()) {