Skip to content

Commit

Permalink
Fix transaction delete issue
Browse files Browse the repository at this point in the history
  • Loading branch information
harshjagad20-dev committed Mar 2, 2022
1 parent ffa7906 commit 5720803
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ public function deleteCompany($user)
if ($this->invoices()->exists()) {
$this->invoices->map(function ($invoice) {
$this->checkModelData($invoice);

if ($invoice->transactions()->exists()) {
$invoice->transactions()->delete();
}
});

$this->invoices()->delete();
Expand Down
7 changes: 6 additions & 1 deletion app/Models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ public static function deleteCustomers($ids)
}

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()) {
Expand Down

0 comments on commit 5720803

Please sign in to comment.