wip stuff

This commit is contained in:
slong753 2023-07-13 00:43:48 -05:00 committed by spencerrlongg
parent a49d3fe131
commit 8456b3ec0c
2 changed files with 64 additions and 0 deletions

View file

@ -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'));
// }
}
}

View file

@ -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) {
//
});
}
}