Skip to content

A free open source IT asset/license management system

wip stuff

slong7538456b3ec0c9c
diff --git a/app/Observers/AssetObserver.php b/app/Observers/AssetObserver.php
index 636f159b65..cf963f78e1 100644
--- a/app/Observers/AssetObserver.php
+++ b/app/Observers/AssetObserver.php
@@ -119,4 +119,15 @@ class AssetObserver
$logAction->user_id = Auth::id();
$logAction->logaction('delete');
}
+
+ public function saving(Asset $asset)
+ {
+ //turning this off for right now so i can check out the note in the migration
+
+ //calculate and set the EOL date if it is not already set
+ // if(is_null($asset->asset_eol_date) && !is_null($asset->asset_purchase_date) && !is_null($asset->model()->get()->eol)){
+ // $asset->asset_eol_date = date('Y-m-d', strtotime($asset->asset_purchase_date . ' + ' . $asset->asset_warranty_months . ' months'));
+ // }
+
+ }
}
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
new file mode 100644
index 0000000000..8975eeeba5
--- /dev/null
+++ b/database/migrations/2023_07_13_052204_denormalized_eol_and_add_column_for_explicit_date_to_assets.php
@@ -0,0 +1,53 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+
+class DenormalizedEolAndAddColumnForExplicitDateToAssets extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('assets', function (Blueprint $table) {
+ $table->date('eol_explicit')->after('asset_eol_date')->nullable();
+ });
+
+ // this is really just a scratch pad for the next step... but it might actually work?
+ // need to check out some things before trying it out, specifically whether or not
+ // asset_eol_date is only actually set when it's custom
+ $customEolAssets = DB::table('assets')->whereNotNull('eol_explicit')->get();
+ foreach ($customEolAssets as $asset) {
+ DB::table('assets')->where('id', $asset->id)->update(['asset_eol_date' => $asset->eol_explicit]);
+ }
+
+ $assets = DB::table('assets')->whereNull('asset_eol_date')->get();
+ foreach ($assets as $asset) {
+ $model = DB::table('models')->where('id', $asset->model_id)->first();
+ if ($model) {
+ $eol = $model->eol;
+ if ($eol) {
+ $asset_eol_date = date('Y-m-d', strtotime($asset->asset_purchase_date . ' + ' . $eol . ' months'));
+ DB::table('assets')->where('id', $asset->id)->update(['asset_eol_date' => $asset_eol_date]);
+ }
+ }
+ }
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('assets', function (Blueprint $table) {
+ //
+ });
+ }
+}