A free open source IT asset/license management system
add diminishing depreciation to selects
Godfrey M80bab383fb12
diff --git a/app/Http/Controllers/DepreciationsController.php b/app/Http/Controllers/DepreciationsController.phpindex 6ceec0048c..4c6cac2694 100755--- a/app/Http/Controllers/DepreciationsController.php+++ b/app/Http/Controllers/DepreciationsController.php@@ -6,6 +6,7 @@ use App\Models\Depreciation;use Illuminate\Contracts\View\View;use Illuminate\Http\RedirectResponse;use Illuminate\Http\Request;+use App\Models\Setting;/*** This controller handles all actions related to Depreciations for@@ -44,7 +45,7 @@ class DepreciationsController extends Controller$this->authorize('create', Depreciation::class);// Show the page- return view('depreciations/edit')->with('item', new Depreciation);+ return view('depreciations/edit')->with('item', new Depreciation)->with('depreciation_method', Setting::getSettings()->depreciation_method);}/**@@ -106,7 +107,7 @@ class DepreciationsController extends Controller$this->authorize('update', $depreciation);- return view('depreciations/edit')->with('item', $depreciation);+ return view('depreciations/edit')->with('item', $depreciation)->with('depreciation_method', Setting::getSettings()->depreciation_method);}/**diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.phpindex 4b1ca6d8fa..1d193eea7a 100644--- a/app/Models/Depreciable.php+++ b/app/Models/Depreciable.php@@ -57,7 +57,9 @@ class Depreciable extends SnipeModelcase 'half_2':$depreciation = $this->getHalfYearDepreciatedValue(false);break;-+ case 'diminish':+ $depreciation = $this->getDiminishingDepreciationValue();+ break;default:$depreciation = $this->getLinearDepreciatedValue();}@@ -132,6 +134,33 @@ class Depreciable extends SnipeModelreturn $this->purchase_cost - round($yearsPast / $deprecationYears * $this->purchase_cost, 2);}+ public function getDiminishingDepreciationValue()+ {+ $depreciation = $this->get_depreciation();++ if (!$depreciation || !$this->purchase_date) {+ return null;+ }++ if ($depreciation->months <= 0) {+ return $this->purchase_cost;+ }++ $purchaseDate = $this->purcahse_date->copy()->startOfDay();+ $currentDate = now()->startOfDay();++ if ($currentDate->lessThaOrEqualTo($purchaseDate)) {+ return $this->purchase_cost;+ }++ $baseValue = $this->purchase_cost;+ $effectiveLife = $depreciation->months / 12;+ $diminishingRate = 2 / $effectiveLife;++ $periodStart = $purchaseDate->copy();+++ }/*** @param \DateTime $date* @return intdiff --git a/resources/lang/en-US/admin/depreciations/general.php b/resources/lang/en-US/admin/depreciations/general.phpindex 57e83da8c5..351fa6435d 100644--- a/resources/lang/en-US/admin/depreciations/general.php+++ b/resources/lang/en-US/admin/depreciations/general.php@@ -15,6 +15,7 @@ return [Please set up at least one depreciation to view the depreciation report.','depreciation_method' => 'Depreciation Report','linear_depreciation' => 'Linear (Default)',+ 'diminishing_depreciation' => 'Diminishing Value Depreciation','half_1' => 'Half-year convention, always applied','half_2' => 'Half-year convention, applied with condition',];diff --git a/resources/views/depreciations/edit.blade.php b/resources/views/depreciations/edit.blade.phpindex d34c149008..2553163ba6 100755--- a/resources/views/depreciations/edit.blade.php+++ b/resources/views/depreciations/edit.blade.php@@ -53,7 +53,9 @@<div style="display: flex;"><input class="form-control" name="depreciation_min" id="depreciation_min" required type="number" value="{{ old('depreciation_min', $item->depreciation_min) }}" style="width: 90px; margin-right: 15px; display: inline-block;" /><select class="form-control select2" name="depreciation_type" id="depreciation_type" data-minimum-results-for-search="Infinity" style="width: 150px; display: inline-block;">- <option value="amount" {{ old('depreciation_type', $item->depreciation_type) == 'amount' ? 'selected' : '' }}>{{ trans('general.depreciation_options.amount') }}</option>+ @if($depreciation_method !== 'diminish')+ <option value="amount" {{ old('depreciation_type', $item->depreciation_type) == 'amount' ? 'selected' : '' }}>{{ trans('general.depreciation_options.amount') }}</option>+ @endif<option value="percent" {{ old('depreciation_type', $item->depreciation_type) == 'percent' ? 'selected' : '' }}>{{ trans('general.depreciation_options.percent') }}</option></select></div>diff --git a/resources/views/settings/general.blade.php b/resources/views/settings/general.blade.phpindex 0b0f66b7fe..e0faa1605d 100644--- a/resources/views/settings/general.blade.php+++ b/resources/views/settings/general.blade.php@@ -409,7 +409,7 @@<x-input.selectname="depreciation_method"id="depreciation_method"- :options="['default' => trans('admin/depreciations/general.linear_depreciation'), 'half_1' => trans('admin/depreciations/general.half_1'), 'half_2' => trans('admin/depreciations/general.half_2')]"+ :options="['default' => trans('admin/depreciations/general.linear_depreciation'), 'diminish' => trans('admin/depreciations/general.diminishing_depreciation'), 'half_1' => trans('admin/depreciations/general.half_1'), 'half_2' => trans('admin/depreciations/general.half_2')]":selected="old('depreciation_method', $setting->depreciation_method)"style="width: 80%"/>