Merge pull request #9937 from Godmartinz/depreciation_min_feature

adds a Floor value for depreciation models
This commit is contained in:
snipe 2021-08-16 18:29:48 -07:00 committed by GitHub
commit 4c13ddd0c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 83 additions and 3 deletions

View file

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

View file

@ -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()) {

View file

@ -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'] = [

View file

@ -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;
}

View file

@ -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,

View file

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

View file

@ -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',

View file

@ -6,5 +6,6 @@ return [
'months' => 'Months',
'term' => 'Term',
'title' => 'Name ',
'depreciation_min' => 'Floor Value',
];

View file

@ -4,10 +4,11 @@ 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',
'current_value' => 'Current Value',
'diff' => 'Diff',
'dl_csv' => 'Download CSV',
'eol' => 'EOL',

View file

@ -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

View file

@ -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">