From d61620bcf6ea85367f4f56070a3474b7e53e51d4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 14 Dec 2022 11:50:55 +1100 Subject: [PATCH] Refactor to use vendor currencies for purchase orders --- app/Console/Commands/CheckData.php | 2 +- ...22_12_14_004639_vendor_currency_update.php | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2022_12_14_004639_vendor_currency_update.php diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 11d4cbc1961c..cc236aac364d 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -991,7 +991,7 @@ class CheckData extends Command if ($this->option('fix') == 'true') { - Vendor::query()->whereNull('currency_id')->cursor()->each(function ($vendor){ + Vendor::query()->whereNull('currency_id')->orWhere('currency_id', '')->cursor()->each(function ($vendor){ $vendor->currency_id = $vendor->company->settings->currency_id; $vendor->save(); diff --git a/database/migrations/2022_12_14_004639_vendor_currency_update.php b/database/migrations/2022_12_14_004639_vendor_currency_update.php new file mode 100644 index 000000000000..990af9e211ed --- /dev/null +++ b/database/migrations/2022_12_14_004639_vendor_currency_update.php @@ -0,0 +1,34 @@ +whereNull('currency_id')->orWhere('currency_id', '')->cursor()->each(function ($vendor){ + + $vendor->currency_id = $vendor->company->settings->currency_id; + $vendor->save(); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +};