A free open source IT asset/license management system
bit of formatting
Godfrey Mda056290b82e
diff --git a/app/Http/Controllers/DepreciationsController.php b/app/Http/Controllers/DepreciationsController.phpindex f3258c377b..534c7fc12f 100755--- a/app/Http/Controllers/DepreciationsController.php+++ b/app/Http/Controllers/DepreciationsController.php@@ -7,6 +7,7 @@ use Illuminate\Contracts\View\View;use Illuminate\Http\RedirectResponse;use Illuminate\Http\Request;use App\Models\Setting;+use Illuminate\Validation\Rule;/*** This controller handles all actions related to Depreciations for@@ -66,18 +67,31 @@ class DepreciationsController extends Controller$depreciation->name = $request->input('name');$depreciation->months = $request->input('months');$depreciation->created_by = auth()->id();+ $isDiminishing = $depreciation->depreciation_method === 'diminish';$request->validate(['depreciation_min' => [- 'required',+ Rule::requiredIf($isDiminishing),'numeric',+ 'nullable',function ($attribute, $value, $fail) use ($request) {if ($request->input('depreciation_type') == 'percent' && ($value < 0 || $value > 100)) {$fail(trans('validation.percent'));}},],- 'depreciation_type' => 'required|in:amount,percent',+ 'depreciation_type' => Rule::requiredIf($isDiminishing),+ 'nullable|in:amount,percent',+ 'rate_multiplier' => [+ Rule::requiredIf($isDiminishing),+ 'nullable',+ 'numeric',+ ],+ 'fiscal_year_start_month' => [+ Rule::requiredIf($isDiminishing),+ 'nullable',+ 'numeric',+ ],]);$depreciation->depreciation_type = $request->input('depreciation_type');$depreciation->depreciation_min = $request->input('depreciation_min');@@ -129,18 +143,31 @@ class DepreciationsController extends Controller$this->authorize('update', $depreciation);$depreciation->name = $request->input('name');$depreciation->months = $request->input('months');+ $isDiminishing = $depreciation->depreciation_method === 'diminish';$request->validate(['depreciation_min' => [- 'required',+ Rule::requiredIf($isDiminishing),'numeric',+ 'nullable',function ($attribute, $value, $fail) use ($request) {if ($request->input('depreciation_type') == 'percent' && ($value < 0 || $value > 100)) {$fail(trans('validation.percent'));}},],- 'depreciation_type' => 'required|in:amount,percent',+ 'depreciation_type' => Rule::requiredIf($isDiminishing),+ 'nullable|in:amount,percent',+ 'rate_multiplier' => [+ Rule::requiredIf($isDiminishing),+ 'nullable',+ 'numeric',+ ],+ 'fiscal_year_start_month' => [+ Rule::requiredIf($isDiminishing),+ 'nullable',+ 'numeric',+ ],]);$depreciation->depreciation_type = $request->input('depreciation_type');$depreciation->depreciation_min = $request->input('depreciation_min');diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.phpindex 8e1b4f73b8..f38e15d86c 100644--- a/app/Models/Depreciable.php+++ b/app/Models/Depreciable.php@@ -98,6 +98,10 @@ class Depreciable extends SnipeModelpublic function getMonthlyDepreciation(){+ $setting = Setting::getSettings();+ if ($setting->depreciation_method === 'diminish') {+ return null;+ }return ($this->purchase_cost - $this->calculateDepreciation()) / $this->get_depreciation()->months;@@ -164,16 +168,8 @@ class Depreciable extends SnipeModelwhile ($periodStart->lessThanOrEqualTo($currentDate) && $baseValue > 0) {$fiscalYearStart = $periodStart->month >= $fiscalYearStartMonth- ? $periodStart->copy()->setDate(- $periodStart->year,- $fiscalYearStartMonth,- 1- )- : $periodStart->copy()->setDate(- $periodStart->year - 1,- $fiscalYearStartMonth,- 1- );+ ? $periodStart->copy()->setDate($periodStart->year, $fiscalYearStartMonth, 1)+ : $periodStart->copy()->setDate($periodStart->year - 1, $fiscalYearStartMonth, 1);$fiscalYearEnd = $fiscalYearStart->copy()->addYear()->subDay();diff --git a/resources/views/depreciations/edit.blade.php b/resources/views/depreciations/edit.blade.phpindex d407c15ecc..49b74f99a4 100755--- a/resources/views/depreciations/edit.blade.php+++ b/resources/views/depreciations/edit.blade.php@@ -75,29 +75,31 @@:max="3600"input_div_class="col-md-2"/>-{{-- Depreciation minimum: an input plus an "amount / percent" selecton the same row. Uses <x-form.row>'s <x-slot:input> so thelabel, error placement, and grid still come from the rowwrapper; only the input area itself is hand-authored. --}}- <x-form.row- :label="trans('admin/depreciations/general.depreciation_min')"- name="depreciation_min"- input_div_class="col-md-9"- >- <x-slot:input>- <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;">- @if($depreciation_method !== 'diminish')+ @if($depreciation_method !== 'diminish')+ <x-form.row+ :label="trans('admin/depreciations/general.depreciation_min')"+ name="depreciation_min"+ input_div_class="col-md-9"+ >+ <x-slot:input>+ <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>- @endif- <option value="percent" {{ old('depreciation_type', $item->depreciation_type) == 'percent' ? 'selected' : '' }}>{{ trans('general.depreciation_options.percent') }}</option>- </select>- </div>- </x-slot:input>- </x-form.row>-+ <option value="percent" {{ old('depreciation_type', $item->depreciation_type) == 'percent' ? 'selected' : '' }}>{{ trans('general.depreciation_options.percent') }}</option>+ </select>+ </div>+ </x-slot:input>+ </x-form.row>+ @endif</x-box></x-form>