Skip to content

A free open source IT asset/license management system

adds a Floor value for depreciation models

Godfrey Mcef0e424e139
diff --git a/app/Http/Controllers/Api/DepreciationsController.php b/app/Http/Controllers/Api/DepreciationsController.php
index 1701deebfb..2dd6b9d8e5 100644
--- a/app/Http/Controllers/Api/DepreciationsController.php
+++ b/app/Http/Controllers/Api/DepreciationsController.php
@@ -20,9 +20,9 @@ class DepreciationsController extends Controller
public function index(Request $request)
{
$this->authorize('view', Depreciation::class);
- $allowed_columns = ['id', 'name', 'months', 'created_at'];
+ $allowed_columns = ['id','name','months','depreciation_min','created_at'];
- $depreciations = Depreciation::select('id', 'name', 'months', 'user_id', 'created_at', 'updated_at');
+ $depreciations = Depreciation::select('id','name','months','depreciation_min','user_id','created_at','updated_at');
if ($request->filled('search')) {
$depreciations = $depreciations->TextSearch($request->input('search'));
diff --git a/app/Http/Controllers/DepreciationsController.php b/app/Http/Controllers/DepreciationsController.php
index c49bc21c4a..d099ce08ed 100755
--- a/app/Http/Controllers/DepreciationsController.php
+++ b/app/Http/Controllers/DepreciationsController.php
@@ -69,6 +69,7 @@ class DepreciationsController extends Controller
$depreciation->name = $request->input('name');
$depreciation->months = $request->input('months');
$depreciation->user_id = Auth::id();
+ $depreciation->depreciation_min = $request->input('depreciation_min');
// Was the asset created?
if ($depreciation->save()) {
@@ -126,6 +127,7 @@ class DepreciationsController extends Controller
// Depreciation data
$depreciation->name = $request->input('name');
$depreciation->months = $request->input('months');
+ $depreciation->depreciation_min = $request->input('depreciation_min');
// Was the asset created?
if ($depreciation->save()) {
diff --git a/app/Http/Transformers/DepreciationsTransformer.php b/app/Http/Transformers/DepreciationsTransformer.php
index b2e1c91739..052f547107 100644
--- a/app/Http/Transformers/DepreciationsTransformer.php
+++ b/app/Http/Transformers/DepreciationsTransformer.php
@@ -27,6 +27,7 @@ class DepreciationsTransformer
'months' => $depreciation->months.' '.trans('general.months'),
'created_at' => Helper::getFormattedDateObject($depreciation->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($depreciation->updated_at, 'datetime'),
+ 'depreciation_min' =>($depreciation->depreciation_min),
];
$permissions_array['available_actions'] = [
diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php
index 1492ea1965..35f494233b 100644
--- a/app/Models/Depreciable.php
+++ b/app/Models/Depreciable.php
@@ -72,6 +72,10 @@ class Depreciable extends SnipeModel
$months_remaining = $this->time_until_depreciated()->m + 12 * $this->time_until_depreciated()->y; //UGlY
$current_value = round(($months_remaining / $this->get_depreciation()->months) * $this->purchase_cost, 2);
+ if($this->get_depreciation()->depreciation_min > $current_value) {
+
+ $current_value=$this->get_depreciation()->depreciation_min;
+ }
if ($current_value < 0) {
$current_value = 0;
}
diff --git a/app/Presenters/DepreciationPresenter.php b/app/Presenters/DepreciationPresenter.php
index c0ff037988..2a293a46ff 100644
--- a/app/Presenters/DepreciationPresenter.php
+++ b/app/Presenters/DepreciationPresenter.php
@@ -38,6 +38,13 @@ class DepreciationPresenter extends Presenter
'visible' => true,
],
+ [
+ "field" => 'depreciation_min',
+ "searchable" => false,
+ "sortable" => true,
+ "title" => trans('admin/depreciations/table.depreciation_min'),
+ "visible" => true,
+ ],
[
'field' => 'actions',
'searchable' => false,
diff --git a/database/migrations/2021_08_17_005043_add_depreciation_minimum_value.php b/database/migrations/2021_08_17_005043_add_depreciation_minimum_value.php
new file mode 100644
index 0000000000..007fb77c0f
--- /dev/null
+++ b/database/migrations/2021_08_17_005043_add_depreciation_minimum_value.php
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddDepreciationMinimumValue extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('depreciations', function (Blueprint $table) {
+ $table->decimal('depreciation_min', 8,2)->after('months')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('depreciations', function (Blueprint $table) {
+ $table->dropColumn('depreciation_min');
+ });
+ }
+}
\ No newline at end of file
diff --git a/resources/lang/en/admin/depreciations/general.php b/resources/lang/en/admin/depreciations/general.php
index e0b02c009d..a17e1816eb 100644
--- a/resources/lang/en/admin/depreciations/general.php
+++ b/resources/lang/en/admin/depreciations/general.php
@@ -6,6 +6,7 @@ return [
'asset_depreciations' => 'Asset Depreciations',
'create' => 'Create Depreciation',
'depreciation_name' => 'Depreciation Name',
+ 'depreciation_min' => 'Floor Value of Depreciation',
'number_of_months' => 'Number of Months',
'update' => 'Update Depreciation',
diff --git a/resources/lang/en/admin/depreciations/table.php b/resources/lang/en/admin/depreciations/table.php
index a0d32d968d..256b10b92a 100644
--- a/resources/lang/en/admin/depreciations/table.php
+++ b/resources/lang/en/admin/depreciations/table.php
@@ -6,5 +6,6 @@ return [
'months' => 'Months',
'term' => 'Term',
'title' => 'Name ',
+ 'depreciation_min' => 'Floor Value',
];
diff --git a/resources/lang/en/admin/hardware/table.php b/resources/lang/en/admin/hardware/table.php
index e992b9d2a7..0f2dbc331b 100644
--- a/resources/lang/en/admin/hardware/table.php
+++ b/resources/lang/en/admin/hardware/table.php
@@ -8,6 +8,7 @@ return [
'change' => 'In/Out',
'checkout_date' => 'Checkout Date',
'checkoutto' => 'Checked Out',
+ 'current_value' => 'Current Value',
'diff' => 'Diff',
'dl_csv' => 'Download CSV',
'eol' => 'EOL',
diff --git a/resources/views/depreciations/edit.blade.php b/resources/views/depreciations/edit.blade.php
index 95df4eda1a..ce8dba8a8e 100755
--- a/resources/views/depreciations/edit.blade.php
+++ b/resources/views/depreciations/edit.blade.php
@@ -22,5 +22,15 @@
</div>
{!! $errors->first('months', '<span class="alert-msg" aria-hidden="true"><i class="fa fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
+<!-- Depreciation Minimum -->
+<div class="form-group {{ $errors->has('depreciation_min') ? ' has-error' : '' }}">
+ <label for="depreciation_min" class="col-md-3 control-label">
+ {{ trans('admin/depreciations/general.depreciation_min') }}
+ </label>
+ <div class="col-md-2" style="padding-left:0px">
+ <input class="form-control" name="depreciation_min" id="depreciation_min" value="{{ Request::old('depreciation_min', $item->depreciation_min) }}" style="width: 80px; margin-left:15px" />
+ </div>
+ {!! $errors->first('depreciation_min', '<span class="alert-msg" aria-hidden="true"><i class="fa fa-times" aria-hidden="true"></i> :message</span>') !!}
+</div>
@stop
diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php
index 3b9dfb4f59..8ba80d224f 100755
--- a/resources/views/hardware/view.blade.php
+++ b/resources/views/hardware/view.blade.php
@@ -463,7 +463,28 @@
</div>
</div>
@endif
+ @if (($asset->model) && ($asset->depreciation))
+ <div class="row">
+ <div class="col-md-2">
+ <strong>
+ {{ trans('admin/hardware/table.current_value') }}
+ </strong>
+ </div>
+ <div class="col-md-6">
+ <div class="col-md-6" style="margin-left:-15px;">
+ @if (($asset->id) && ($asset->location))
+ {{ $asset->location->currency }}
+ @elseif (($asset->id) && ($asset->location))
+ {{ $asset->location->currency }}
+ @else
+ {{ $snipeSettings->default_currency }}
+ @endif
+ {{ \App\Helpers\Helper::formatCurrencyOutput($asset->getDepreciatedValue() )}}
+ </div>
+ </div>
+ </div>
+ @endif
@if ($asset->order_number)
<div class="row">
<div class="col-md-2">