a little cleanup

This commit is contained in:
spencerrlongg 2023-08-15 20:14:11 -05:00
parent e1af69f6ae
commit c66804bcee
4 changed files with 4 additions and 10 deletions

View file

@ -123,12 +123,10 @@ class AssetImporter extends ItemImporter
$item['asset_eol_date'] = null; $item['asset_eol_date'] = null;
if (isset($this->item['asset_eol_date'])) { if (isset($this->item['asset_eol_date'])) {
$model = AssetModel::find($this->createOrFetchAssetModel($row, $this->item['model_id'])); $model = AssetModel::find($this->createOrFetchAssetModel($row, $this->item['model_id']));
ray(['model!' => $model]);
if(is_null($model->eol)) { if(is_null($model->eol)) {
$item['asset_eol_date'] = Carbon::parse($this->item['asset_eol_date'])->format('Y-m-d'); $item['asset_eol_date'] = Carbon::parse($this->item['asset_eol_date'])->format('Y-m-d');
$item['eol_explicit'] = true; $item['eol_explicit'] = true;
} elseif (!is_null($model->eol) && !is_null($this->item['purchase_date'])) { } 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');
} }
} }

View file

@ -10,7 +10,6 @@ use App\Models\Manufacturer;
use App\Models\Statuslabel; use App\Models\Statuslabel;
use App\Models\Supplier; use App\Models\Supplier;
use App\Models\User; use App\Models\User;
use Carbon\Carbon;
class ItemImporter extends Importer class ItemImporter extends Importer
{ {

View file

@ -123,7 +123,6 @@ class AssetObserver
public function saving(Asset $asset) 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 //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)){ 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'); $asset->asset_eol_date = $asset->purchase_date->addMonths($asset->model->eol)->format('Y-m-d');

View file

@ -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 // Update the asset_eol_date column with the calculated value if it doesn't exist
$assets = Asset::whereNull('asset_eol_date')->get(); $assets = Asset::whereNull('asset_eol_date')->get();
foreach ($assets as $asset) { foreach ($assets as $asset) {
$model = Asset::find($asset->id)->model; $model = Asset::find($asset->id)->model;
if ($model) { if (!empty($model->eol)) {
$eol = $model->eol; $asset_eol_date = Carbon::parse($asset->purchase_date)->addMonths($model->eol)->format('Y-m-d');
if ($eol) {
$asset_eol_date = Carbon::parse($asset->purchase_date)->addMonths($eol)->format('Y-m-d');
$asset->update(['asset_eol_date' => $asset_eol_date]); $asset->update(['asset_eol_date' => $asset_eol_date]);
} }
} }
} }
}
/** /**
* Reverse the migrations. * Reverse the migrations.