diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 31ccdc2908f7..b4402a4bb7fa 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -169,26 +169,21 @@ class CheckData extends Command private function checkCompanyTokens() { - // CompanyUser::whereDoesntHave('token', function ($query){ - // return $query->where('is_system', 1); - // })->cursor()->each(function ($cu){ - // if ($cu->user) { - // $this->logMessage("Creating missing company token for user # {$cu->user->id} for company id # {$cu->company->id}"); - // (new CreateCompanyToken($cu->company, $cu->user, 'System'))->handle(); - // } else { - // $this->logMessage("Dangling User ID # {$cu->id}"); - // } - // }); - CompanyUser::query()->cursor()->each(function ($cu) { + if (CompanyToken::where('user_id', $cu->user_id)->where('company_id', $cu->company_id)->where('is_system', 1)->doesntExist()) { - $this->logMessage("Creating missing company token for user # {$cu->user_id} for company id # {$cu->company_id}"); + if ($cu->company && $cu->user) { + $this->logMessage("Creating missing company token for user # {$cu->user_id} for company id # {$cu->company_id}"); (new CreateCompanyToken($cu->company, $cu->user, 'System'))->handle(); - } else { - // $cu->forceDelete(); + } + + if (!$cu->user) { + $this->logMessage("No user found for company user - removing company user"); + $cu->forceDelete(); } + } }); } @@ -482,6 +477,14 @@ class CheckData extends Command } } else { $this->logMessage("No contact present, so cannot add invitation for {$entity_key} - {$entity->id}"); + + try{ + $entity->service()->createInvitations()->save(); + } + catch(\Exception $e){ + + } + } try { diff --git a/app/Helpers/Invoice/InvoiceSum.php b/app/Helpers/Invoice/InvoiceSum.php index 52cd745418e6..37ef67318927 100644 --- a/app/Helpers/Invoice/InvoiceSum.php +++ b/app/Helpers/Invoice/InvoiceSum.php @@ -246,6 +246,8 @@ class InvoiceSum if ($this->invoice->status_id != Invoice::STATUS_DRAFT) { if ($this->invoice->amount != $this->invoice->balance) { + // $paid_to_date = $this->invoice->amount - $this->invoice->balance; + $this->invoice->balance = Number::roundValue($this->getTotal(), $this->precision) - $this->invoice->paid_to_date; //21-02-2024 cannot use the calculated $paid_to_date here as it could send the balance backward. } else { $this->invoice->balance = Number::roundValue($this->getTotal(), $this->precision);