mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
adds migration for explicit purchase cost added
This commit is contained in:
parent
90c41d9510
commit
853333911f
|
@ -75,6 +75,7 @@ class AssetModelsController extends Controller
|
|||
$model->name = $request->input('name');
|
||||
$model->model_number = $request->input('model_number');
|
||||
$model->min_amt = $request->input('min_amt');
|
||||
$model->default_purchase_cost = $request->input('purchase_cost');
|
||||
$model->manufacturer_id = $request->input('manufacturer_id');
|
||||
$model->category_id = $request->input('category_id');
|
||||
$model->notes = $request->input('notes');
|
||||
|
@ -146,6 +147,7 @@ class AssetModelsController extends Controller
|
|||
$model->name = $request->input('name');
|
||||
$model->model_number = $request->input('model_number');
|
||||
$model->min_amt = $request->input('min_amt');
|
||||
$model->default_purchase_cost = $request->input('purchase_cost');
|
||||
$model->manufacturer_id = $request->input('manufacturer_id');
|
||||
$model->category_id = $request->input('category_id');
|
||||
$model->notes = $request->input('notes');
|
||||
|
@ -172,6 +174,12 @@ class AssetModelsController extends Controller
|
|||
->update(['asset_eol_date' => DB::raw('null')]);
|
||||
}
|
||||
}
|
||||
if($model->wasChanged('default_purchase_cost')){
|
||||
if ($model->purchase_cost != '') {
|
||||
$model->assets()->whereNotNull('purchase_cost')->where('cost_explicit', false)
|
||||
->update(['purchase_cost']);
|
||||
}
|
||||
}
|
||||
return redirect()->route('models.index')->with('success', trans('admin/models/message.update.success'));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Asset;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
|
@ -11,8 +12,27 @@ return new class extends Migration
|
|||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('assets', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('assets', 'purchase_cost_explicit')) {
|
||||
$table->boolean('purchase_cost_explicit')->default(false)->after('purchase_cost');
|
||||
}
|
||||
});
|
||||
|
||||
Schema::table('models', function (Blueprint $table) {
|
||||
//
|
||||
$table->decimal('default_purchase_cost', 8, 2)->default(null)->nullable()->after('min_amt');
|
||||
});
|
||||
|
||||
Asset::whereNotNull('purchase_cost')->with('model')->chunkById(500, function ($assetsWithPurchaseCosts) {
|
||||
foreach ($assetsWithPurchaseCosts as $asset) {
|
||||
if($asset->purchase_cost) {
|
||||
if ($asset->purchase_cost !== $asset->model->default_purchase_cost) {
|
||||
DB::table('assets')->where('id', $asset->id)->update(['purchase_cost_explicit' => true]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DB::table('assets')->where('id', $asset->id)->update(['purchase_cost_explicit' => false]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -21,8 +41,12 @@ return new class extends Migration
|
|||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('assets', function (Blueprint $table) {
|
||||
$table->dropColumn('purchase_cost_explicit');
|
||||
});
|
||||
|
||||
Schema::table('models', function (Blueprint $table) {
|
||||
//
|
||||
$table->dropColumn('default_purchase_cost');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue