From cef0e424e139a0e548a7929f8cf07c0c67c80111 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 16 Aug 2021 18:14:10 -0700 Subject: [PATCH 1/2] adds a Floor value for depreciation models --- .../Api/DepreciationsController.php | 4 +-- .../Controllers/DepreciationsController.php | 2 ++ .../Transformers/DepreciationsTransformer.php | 1 + app/Models/Depreciable.php | 4 +++ app/Presenters/DepreciationPresenter.php | 7 ++++ ..._005043_add_depreciation_minimum_value.php | 32 +++++++++++++++++++ .../lang/en/admin/depreciations/general.php | 1 + .../lang/en/admin/depreciations/table.php | 1 + resources/lang/en/admin/hardware/table.php | 1 + resources/views/depreciations/edit.blade.php | 10 ++++++ resources/views/hardware/view.blade.php | 21 ++++++++++++ 11 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2021_08_17_005043_add_depreciation_minimum_value.php 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 @@ +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 @@ {!! $errors->first('months', '') !!} + +
+ +
+ +
+ {!! $errors->first('depreciation_min', '') !!} +
@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 @@ @endif + @if (($asset->model) && ($asset->depreciation)) +
+
+ + {{ trans('admin/hardware/table.current_value') }} + +
+
+
+ @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() )}} +
+
+
+ @endif @if ($asset->order_number)
From 9480709ea35aecab6ea7ac141466bad27fa0f2ec Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 16 Aug 2021 18:22:24 -0700 Subject: [PATCH 2/2] changed value to current value --- resources/lang/en/admin/hardware/table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/admin/hardware/table.php b/resources/lang/en/admin/hardware/table.php index 0f2dbc331b..828990b6e4 100644 --- a/resources/lang/en/admin/hardware/table.php +++ b/resources/lang/en/admin/hardware/table.php @@ -4,7 +4,7 @@ return [ 'asset_tag' => 'Asset Tag', 'asset_model' => 'Model', - 'book_value' => 'Value', + 'book_value' => 'Current Value', 'change' => 'In/Out', 'checkout_date' => 'Checkout Date', 'checkoutto' => 'Checked Out',