mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
updates assets when model is updated, renamed default_purchase_cost
This commit is contained in:
parent
a440f6f87c
commit
0c75d41751
|
@ -75,7 +75,7 @@ class AssetModelsController extends Controller
|
||||||
$model->name = $request->input('name');
|
$model->name = $request->input('name');
|
||||||
$model->model_number = $request->input('model_number');
|
$model->model_number = $request->input('model_number');
|
||||||
$model->min_amt = $request->input('min_amt');
|
$model->min_amt = $request->input('min_amt');
|
||||||
$model->default_purchase_cost = $request->input('purchase_cost');
|
$model->purchase_cost = $request->input('purchase_cost');
|
||||||
$model->manufacturer_id = $request->input('manufacturer_id');
|
$model->manufacturer_id = $request->input('manufacturer_id');
|
||||||
$model->category_id = $request->input('category_id');
|
$model->category_id = $request->input('category_id');
|
||||||
$model->notes = $request->input('notes');
|
$model->notes = $request->input('notes');
|
||||||
|
@ -147,7 +147,7 @@ class AssetModelsController extends Controller
|
||||||
$model->name = $request->input('name');
|
$model->name = $request->input('name');
|
||||||
$model->model_number = $request->input('model_number');
|
$model->model_number = $request->input('model_number');
|
||||||
$model->min_amt = $request->input('min_amt');
|
$model->min_amt = $request->input('min_amt');
|
||||||
$model->default_purchase_cost = $request->input('purchase_cost');
|
$model->purchase_cost = $request->input('purchase_cost');
|
||||||
$model->manufacturer_id = $request->input('manufacturer_id');
|
$model->manufacturer_id = $request->input('manufacturer_id');
|
||||||
$model->category_id = $request->input('category_id');
|
$model->category_id = $request->input('category_id');
|
||||||
$model->notes = $request->input('notes');
|
$model->notes = $request->input('notes');
|
||||||
|
@ -174,10 +174,10 @@ class AssetModelsController extends Controller
|
||||||
->update(['asset_eol_date' => DB::raw('null')]);
|
->update(['asset_eol_date' => DB::raw('null')]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($model->wasChanged('default_purchase_cost')){
|
if($model->wasChanged('purchase_cost')){
|
||||||
if ($model->purchase_cost != '') {
|
if ($model->purchase_cost !== '') {
|
||||||
$model->assets()->whereNotNull('purchase_cost')->where('cost_explicit', false)
|
$model->assets()->whereNotNull('purchase_cost')->where('purchase_cost_explicit', false)
|
||||||
->update(['purchase_cost']);
|
->update(['purchase_cost' => $model->purchase_cost] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return redirect()->route('models.index')->with('success', trans('admin/models/message.update.success'));
|
return redirect()->route('models.index')->with('success', trans('admin/models/message.update.success'));
|
||||||
|
|
|
@ -138,8 +138,8 @@ class AssetsController extends Controller
|
||||||
if($request->filled('purchase_cost')) {
|
if($request->filled('purchase_cost')) {
|
||||||
$asset->purchase_cost = $request->input('purchase_cost', null);
|
$asset->purchase_cost = $request->input('purchase_cost', null);
|
||||||
}
|
}
|
||||||
else if($asset->model->default_purchase_cost !== null) {
|
else if($asset->model->purchase_cost !== null) {
|
||||||
$asset->purchase_cost = $asset->model->default_purchase_cost;
|
$asset->purchase_cost = $asset->model->purchase_cost;
|
||||||
}
|
}
|
||||||
$asset->purchase_cost_explicit = Asset::purchaseCostExplicit($asset, $request);
|
$asset->purchase_cost_explicit = Asset::purchaseCostExplicit($asset, $request);
|
||||||
$asset->purchase_date = request('purchase_date', null);
|
$asset->purchase_date = request('purchase_date', null);
|
||||||
|
@ -312,8 +312,8 @@ class AssetsController extends Controller
|
||||||
if($request->filled('purchase_cost')) {
|
if($request->filled('purchase_cost')) {
|
||||||
$asset->purchase_cost = $request->input('purchase_cost', null);
|
$asset->purchase_cost = $request->input('purchase_cost', null);
|
||||||
}
|
}
|
||||||
else if($asset->model->default_purchase_cost !== null) {
|
else if($asset->model->purchase_cost !== null) {
|
||||||
$asset->purchase_cost = $asset->model->default_purchase_cost;
|
$asset->purchase_cost = $asset->model->purchase_cost;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$asset->purchase_cost = null;
|
$asset->purchase_cost = null;
|
||||||
|
|
|
@ -971,8 +971,8 @@ class Asset extends Depreciable
|
||||||
public static function purchaseCostExplicit($asset, $request)
|
public static function purchaseCostExplicit($asset, $request)
|
||||||
{
|
{
|
||||||
if ($request->input('purchase_cost')) {
|
if ($request->input('purchase_cost')) {
|
||||||
if ($asset->model->default_purchase_cost) {
|
if ($asset->model->purchase_cost) {
|
||||||
if ($request->input('purchase_cost') !== $asset->model->default_purchase_cost) {
|
if ($request->input('purchase_cost') !== $asset->model->purchase_cost) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -19,13 +19,13 @@ return new class extends Migration
|
||||||
});
|
});
|
||||||
|
|
||||||
Schema::table('models', function (Blueprint $table) {
|
Schema::table('models', function (Blueprint $table) {
|
||||||
$table->decimal('default_purchase_cost', 8, 2)->default(null)->nullable()->after('min_amt');
|
$table->decimal('purchase_cost', 8, 2)->default(null)->nullable()->after('min_amt');
|
||||||
});
|
});
|
||||||
|
|
||||||
Asset::whereNotNull('purchase_cost')->with('model')->chunkById(500, function ($assetsWithPurchaseCosts) {
|
Asset::whereNotNull('purchase_cost')->with('model')->chunkById(500, function ($assetsWithPurchaseCosts) {
|
||||||
foreach ($assetsWithPurchaseCosts as $asset) {
|
foreach ($assetsWithPurchaseCosts as $asset) {
|
||||||
if($asset->purchase_cost) {
|
if($asset->purchase_cost) {
|
||||||
if ($asset->purchase_cost !== $asset->model->default_purchase_cost) {
|
if ($asset->purchase_cost !== $asset->model->purchase_cost) {
|
||||||
DB::table('assets')->where('id', $asset->id)->update(['purchase_cost_explicit' => true]);
|
DB::table('assets')->where('id', $asset->id)->update(['purchase_cost_explicit' => true]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ return new class extends Migration
|
||||||
});
|
});
|
||||||
|
|
||||||
Schema::table('models', function (Blueprint $table) {
|
Schema::table('models', function (Blueprint $table) {
|
||||||
$table->dropColumn('default_purchase_cost');
|
$table->dropColumn('purchase_cost');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<label for="purchase_cost" class="col-md-3 control-label">{{ trans('general.purchase_cost') }}</label>
|
<label for="purchase_cost" class="col-md-3 control-label">{{ trans('general.purchase_cost') }}</label>
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
<div class="input-group col-md-4" style="padding-left: 0px;">
|
<div class="input-group col-md-4" style="padding-left: 0px;">
|
||||||
<input class="form-control" type="text" name="purchase_cost" aria-label="purchase_cost" id="purchase_cost" value="{{ old('purchase_cost', Helper::formatCurrencyOutput($item->purchase_cost)) }}" />
|
<input class="form-control" type="text" name="purchase_cost" aria-label="purchase_cost" id="purchase_cost" value="{{ (old('purchase_cost', Helper::formatCurrencyOutput($item->purchase_cost))) }}" />
|
||||||
<span class="input-group-addon">
|
<span class="input-group-addon">
|
||||||
@if (isset($currency_type))
|
@if (isset($currency_type))
|
||||||
{{ $currency_type }}
|
{{ $currency_type }}
|
||||||
|
|
Loading…
Reference in a new issue