A free open source IT asset/license management system
add depreciation rate multiplier and fiscal year begin values to table and gui
Godfrey M816dd8dd1a18
diff --git a/app/Http/Controllers/DepreciationsController.php b/app/Http/Controllers/DepreciationsController.phpindex 4c6cac2694..f3258c377b 100755--- a/app/Http/Controllers/DepreciationsController.php+++ b/app/Http/Controllers/DepreciationsController.php@@ -81,6 +81,8 @@ class DepreciationsController extends Controller]);$depreciation->depreciation_type = $request->input('depreciation_type');$depreciation->depreciation_min = $request->input('depreciation_min');+ $depreciation->rate_multiplier = $request->input('rate_multiplier');+ $depreciation->fiscal_year_start_month = $request->input('fiscal_year_start_month');// Was the asset created?if ($depreciation->save()) {@@ -142,6 +144,8 @@ class DepreciationsController extends Controller]);$depreciation->depreciation_type = $request->input('depreciation_type');$depreciation->depreciation_min = $request->input('depreciation_min');+ $depreciation->rate_multiplier = $request->input('rate_multiplier');+ $depreciation->fiscal_year_start_month = $request->input('fiscal_year_start_month');// Was the asset created?if ($depreciation->save()) {diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.phpindex 1d193eea7a..8e1b4f73b8 100644--- a/app/Models/Depreciable.php+++ b/app/Models/Depreciable.php@@ -146,20 +146,54 @@ class Depreciable extends SnipeModelreturn $this->purchase_cost;}- $purchaseDate = $this->purcahse_date->copy()->startOfDay();+ $purchaseDate = $this->purchase_date->copy()->startOfDay();$currentDate = now()->startOfDay();- if ($currentDate->lessThaOrEqualTo($purchaseDate)) {+ if ($currentDate->lessThanOrEqualTo($purchaseDate)) {return $this->purchase_cost;}$baseValue = $this->purchase_cost;$effectiveLife = $depreciation->months / 12;- $diminishingRate = 2 / $effectiveLife;++ $rateMultiplier = (float)($depreciation->rate_multiplier ?? 2);+ $fiscalYearStartMonth = (int)($depreciation->fiscal_year_start_month ?? 1);+ $diminishingRate = $rateMultiplier / $effectiveLife;$periodStart = $purchaseDate->copy();+ while ($periodStart->lessThanOrEqualTo($currentDate) && $baseValue > 0) {+ $fiscalYearStart = $periodStart->month >= $fiscalYearStartMonth+ ? $periodStart->copy()->setDate(+ $periodStart->year,+ $fiscalYearStartMonth,+ 1+ )+ : $periodStart->copy()->setDate(+ $periodStart->year - 1,+ $fiscalYearStartMonth,+ 1+ );++ $fiscalYearEnd = $fiscalYearStart->copy()->addYear()->subDay();++ $periodEnd = $currentDate->lessThan($fiscalYearEnd)+ ? $currentDate->copy()+ : $fiscalYearEnd;++ // Both the starting and ending dates count as days held.+ $daysHeld = $periodStart->diffInDays($periodEnd) + 1;++ $declineInValue = $baseValue+ * ($daysHeld / 365)+ * $diminishingRate;++ $baseValue -= min($declineInValue, $baseValue);++ $periodStart = $periodEnd->copy()->addDay();+ }+ return round(max($baseValue, 0), 2);}/*** @param \DateTime $datediff --git a/database/migrations/2026_07_20_172857_add_diminish_method_variables_to_depreciations_table.php b/database/migrations/2026_07_20_172857_add_diminish_method_variables_to_depreciations_table.phpnew file mode 100644index 0000000000..b774bb650c--- /dev/null+++ b/database/migrations/2026_07_20_172857_add_diminish_method_variables_to_depreciations_table.php@@ -0,0 +1,29 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration {+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('depreciations', function (Blueprint $table) {+ $table->string('fiscal_year_start_month')->after('depreciation_min')->nullable();+ $table->float('rate_multiplier')->after('fiscal_year_start_month')->nullable();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('depreciations', function (Blueprint $table) {+ $table->dropColumn('fiscal_year_start_month');+ $table->dropColumn('rate_multiplier');+ });+ }+};diff --git a/resources/lang/en-US/admin/depreciations/general.php b/resources/lang/en-US/admin/depreciations/general.phpindex 351fa6435d..fad48697f6 100644--- a/resources/lang/en-US/admin/depreciations/general.php+++ b/resources/lang/en-US/admin/depreciations/general.php@@ -8,8 +8,9 @@ return ['depreciation_name' => 'Depreciation Name','depreciation_min' => 'Floor Value of Depreciation','number_of_months' => 'Number of Months',+ 'rate_multiplier' => 'Rate Multiplier','update' => 'Update Depreciation',- 'depreciation_min' => 'Minimum Value after Depreciation',+ 'fiscal_year_start_month' => 'Fiscal Year Start Month','no_depreciations_warning' => '<strong>Warning: </strong>You do not currently have any depreciations set up.Please set up at least one depreciation to view the depreciation report.',diff --git a/resources/views/depreciations/edit.blade.php b/resources/views/depreciations/edit.blade.phpindex 2553163ba6..d407c15ecc 100755--- a/resources/views/depreciations/edit.blade.php+++ b/resources/views/depreciations/edit.blade.php@@ -23,13 +23,49 @@<x-form :$item route="{{ (isset($item->id)) ? route('depreciations.update', ['depreciation' => $item->id]) : route('depreciations.store') }}"><x-box>-<x-form.row:label="trans('admin/depreciations/general.depreciation_name')":$itemname="name"/>+ @if($depreciation_method === 'diminish')+ <x-form.row+ :label="trans('admin/depreciations/general.fiscal_year_start_month')"+ :$item+ name="fiscal_year_start_month"+ type="number"+ :min="1"+ :max="12"+ input_div_class="col-md-2"+ />+ <x-form.row+ :label="trans('admin/depreciations/general.rate_multiplier')"+ :$item+ name="rate_multiplier"+ input_div_class="col-md-2"+ >+ <x-slot:input>+ <select+ class="form-control select2"+ name="rate_multiplier"+ id="rate_multiplier"+ data-minimum-results-for-search="Infinity"+ >+ <option value="1.00" {{ old('rate_multiplier', $item->rate_multiplier) == 1.00 ? 'selected' : '' }}>+ 100%+ </option>++ <option value="1.50" {{ old('rate_multiplier', $item->rate_multiplier) == 1.50 ? 'selected' : '' }}>+ 150%+ </option>+ <option value="2.00" {{ old('rate_multiplier', $item->rate_multiplier) == 2.00 ? 'selected' : '' }}>+ 200%+ </option>+ </select>+ </x-slot:input>+ </x-form.row>+ @endif<x-form.row:label="trans('admin/depreciations/general.number_of_months')":$item