diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index dc5610ab4..c13a61d33 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -123,13 +123,11 @@ class AssetImporter extends ItemImporter $item['asset_eol_date'] = null; if (isset($this->item['asset_eol_date'])) { $model = AssetModel::find($this->createOrFetchAssetModel($row, $this->item['model_id'])); - ray(['model!' => $model]); if(is_null($model->eol)) { $item['asset_eol_date'] = Carbon::parse($this->item['asset_eol_date'])->format('Y-m-d'); $item['eol_explicit'] = true; } elseif (!is_null($model->eol) && !is_null($this->item['purchase_date'])) { - ray('EOL is not null'); - $item['asset_eol_date'] = Carbon::parse($this->item['purchase_date'])->addMonths($model->eol)->format('Y-m-d'); + $item['asset_eol_date'] = Carbon::parse($this->item['purchase_date'])->addMonths($model->eol)->format('Y-m-d'); } } diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index 297f81751..256d74d92 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -10,7 +10,6 @@ use App\Models\Manufacturer; use App\Models\Statuslabel; use App\Models\Supplier; use App\Models\User; -use Carbon\Carbon; class ItemImporter extends Importer { diff --git a/app/Observers/AssetObserver.php b/app/Observers/AssetObserver.php index 38fcf0f2d..5e76a73ed 100644 --- a/app/Observers/AssetObserver.php +++ b/app/Observers/AssetObserver.php @@ -123,7 +123,6 @@ class AssetObserver public function saving(Asset $asset) { - ray('THIS FUCKING SHIT DOESNT WORK'); //determine if calculated eol and then calculate it - this should only happen on a new asset if(is_null($asset->asset_eol_date) && !is_null($asset->asset_purchase_date) && !is_null($asset->model->eol)){ $asset->asset_eol_date = $asset->purchase_date->addMonths($asset->model->eol)->format('Y-m-d'); diff --git a/database/migrations/2023_07_13_052204_denormalized_eol_and_add_column_for_explicit_date_to_assets.php b/database/migrations/2023_07_13_052204_denormalized_eol_and_add_column_for_explicit_date_to_assets.php index 1abfd95ad..1eb8d0084 100644 --- a/database/migrations/2023_07_13_052204_denormalized_eol_and_add_column_for_explicit_date_to_assets.php +++ b/database/migrations/2023_07_13_052204_denormalized_eol_and_add_column_for_explicit_date_to_assets.php @@ -34,20 +34,18 @@ class DenormalizedEolAndAddColumnForExplicitDateToAssets extends Migration } } } + unset($assetsWithEolDates); // Update the asset_eol_date column with the calculated value if it doesn't exist $assets = Asset::whereNull('asset_eol_date')->get(); foreach ($assets as $asset) { $model = Asset::find($asset->id)->model; - if ($model) { - $eol = $model->eol; - if ($eol) { - $asset_eol_date = Carbon::parse($asset->purchase_date)->addMonths($eol)->format('Y-m-d'); + if (!empty($model->eol)) { + $asset_eol_date = Carbon::parse($asset->purchase_date)->addMonths($model->eol)->format('Y-m-d'); $asset->update(['asset_eol_date' => $asset_eol_date]); } } } - } /** * Reverse the migrations.