small changes

This commit is contained in:
slong753 2023-07-17 14:37:32 -05:00 committed by spencerrlongg
parent 17a83129b9
commit 41b65bd9a2
2 changed files with 7 additions and 10 deletions

View file

@ -128,6 +128,10 @@ class AssetImporter extends ItemImporter
if (isset($this->item['eol_explicit'])) {
$item['eol_explicit'] = $this->item['eol_explicit'];
}
if(($item['asset_eol_date'] == null) && ($item['eol_explicit'] == null) && ($asset->model->eol != null) && ($asset->asset_purchase_date != null)){
$asset->asset_eol_date = Carbon::parse($asset->asset_purchase_date)->addMonths($asset->model->eol)->format('Y-m-d');
}
if ($editingAsset) {
$asset->update($item);
@ -142,11 +146,6 @@ class AssetImporter extends ItemImporter
}
}
if(($item['asset_eol_date'] == null) && ($item['eol_explicit'] == null) && ($asset->model->eol != null) && ($asset->asset_purchase_date != null)){
$asset->asset_eol_date = Carbon::parse($asset->asset_purchase_date)->addMonths($asset->model->eol)->format('Y-m-d');
}
if ($asset->save()) {
$asset->logCreate(trans('general.importer.import_note'));

View file

@ -2,10 +2,8 @@
use App\Models\Asset;
use Carbon\Carbon;
use Carbon\CarbonInterval;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class DenormalizedEolAndAddColumnForExplicitDateToAssets extends Migration
@ -28,20 +26,20 @@ class DenormalizedEolAndAddColumnForExplicitDateToAssets extends Migration
if($asset->asset_eol_date && $asset->asset_purchase_date) {
$months = Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->asset_purchase_date);
if($months != $asset->model->eol) {
DB::table('assets')->find($asset->id)->update(['eol_explicit' => $asset->asset_eol_date]);
Asset::find($asset->id)->update(['eol_explicit' => $asset->asset_eol_date]);
}
}
}
// Update the asset_eol_date column with the calculated value if it doesn't exist
$assets = DB::table('assets')->whereNull('asset_eol_date')->get();
$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->asset_purchase_date)->addMonths($eol)->format('Y-m-d');
DB::table('assets')->where('id', $asset->id)->update(['asset_eol_date' => $asset_eol_date]);
Asset::fine($asset->id)->update(['asset_eol_date' => $asset_eol_date]);
}
}
}