diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 9edd42f4dfba..94a1c6e105ec 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -890,6 +890,40 @@ class CheckData extends Command $this->logMessage("Fixing country for # {$client->id}"); }); + + Client::query()->whereNull("settings->currency_id")->cursor()->each(function ($client){ + $settings = $client->settings; + $settings->currency_id = (string)$client->company->settings->currency_id; + $client->settings = $settings; + $client->saveQuietly(); + + $this->logMessage("Fixing currency_id for # {$client->id}"); + + }); + + Payment::withTrashed()->where('exchange_rate', 0)->cursor()->each(function ($payment){ + $payment->exchange_rate = 1; + $payment->saveQuietly(); + + $this->logMessage("Fixing exchange rate for # {$payment->id}"); + }); + + Payment::withTrashed() + ->whereHas("client", function ($query) { + $query->whereColumn("settings->currency_id", "!=", "payments.currency_id"); + }) + ->cursor() + ->each(function ($p) { + $p->currency_id = $p->client->settings->currency_id; + $p->saveQuietly(); + + + $this->logMessage("Fixing currency for # {$p->id}"); + + }); + + + } } diff --git a/database/migrations/2024_01_09_084515_product_cost_field_population.php b/database/migrations/2024_01_09_084515_product_cost_field_population.php index fd3ab9a43258..c38dd91d256a 100644 --- a/database/migrations/2024_01_09_084515_product_cost_field_population.php +++ b/database/migrations/2024_01_09_084515_product_cost_field_population.php @@ -28,20 +28,22 @@ return new class extends Migration $line_items = $invoice->line_items; - foreach ($line_items as $key => $item) + if(is_array($line_items)) { - - if($product = Product::where('company_id', $invoice->company_id)->where('product_key', $item->product_key)->where('cost', '>', 0)->first()) + foreach ($line_items as $key => $item) { - if((property_exists($item, 'product_cost') && $item->product_cost == 0) || !property_exists($item, 'product_cost')) - $line_items[$key]->product_cost = (float)$product->cost; + + if($product = Product::where('company_id', $invoice->company_id)->where('product_key', $item->product_key)->where('cost', '>', 0)->first()) + { + if((property_exists($item, 'product_cost') && $item->product_cost == 0) || !property_exists($item, 'product_cost')) + $line_items[$key]->product_cost = (float)$product->cost; + } + } - + + $invoice->line_items = $line_items; + $invoice->saveQuietly(); } - - $invoice->line_items = $line_items; - $invoice->saveQuietly(); - }); }