From 5720803116f377338f1520bdaf8ff92d35f058c3 Mon Sep 17 00:00:00 2001 From: harshjagad20 Date: Wed, 2 Mar 2022 12:17:31 +0530 Subject: [PATCH] Fix transaction delete issue --- app/Models/Company.php | 4 ++++ app/Models/Customer.php | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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()) {