A free open source IT asset/license management system
Fixed 500 when depreciation is set but no purchase_date
snipe24910433a145
diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.phpindex 20a28af40a..e22fb65a7f 100644--- a/app/Models/Depreciable.php+++ b/app/Models/Depreciable.php@@ -68,9 +68,13 @@ class Depreciable extends SnipeModel*/public function getLinearDepreciatedValue() // TODO - for testing it might be nice to have an optional $relative_to param here, defaulted to 'now'{- $months_passed = $this->purchase_date->diff(now())->m;+ if ($this->purchase_date) {+ $months_passed = $this->purchase_date->diff(now())->m;+ } else {+ return null;+ }- if($months_passed >= $this->get_depreciation()->months){+ if ($months_passed >= $this->get_depreciation()->months){//if there is a floor use itif($this->get_depreciation()->deprecation_min->isNotEmpty()) {diff --git a/resources/lang/en/general.php b/resources/lang/en/general.phpindex 6a2bc35080..029b74d195 100644--- a/resources/lang/en/general.php+++ b/resources/lang/en/general.php@@ -372,6 +372,7 @@ return ['bulk_checkin_delete_success' => 'Your selected users have been deleted and their items have been checked in.','bulk_checkin_success' => 'The items for the selected users have been checked in.','set_to_null' => 'Delete values for this asset|Delete values for all :asset_count assets ',+ 'na_no_purchase_date' => 'N/A - No purchase date provided',];\ No newline at end of filediff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.phpindex 2e24d8a62b..5aaed904be 100755--- a/resources/views/hardware/view.blade.php+++ b/resources/views/hardware/view.blade.php@@ -519,7 +519,7 @@</div></div>@endif- @if (($asset->model) && ($asset->depreciation))+ @if (($asset->model) && ($asset->depreciation) && ($asset->purchase_date))<div class="row"><div class="col-md-2"><strong>@@ -597,14 +597,17 @@<strong>{{ trans('admin/hardware/form.warranty_expires') }}{!! $asset->present()->warranty_expires() < date("Y-m-d") ? '<i class="fas fa-exclamation-triangle text-orange" aria-hidden="true"></i>' : '' !!}+</strong></div><div class="col-md-6">-+ @if ($asset->purchase_date){{ Helper::getFormattedDateObject($asset->present()->warranty_expires(), 'date', false) }}-{{ Carbon::parse($asset->present()->warranty_expires())->diffForHumans() }}-+ @else+ {{ trans('general.na_no_purchase_date') }}+ @endif</div></div>@@ -630,9 +633,13 @@</strong></div><div class="col-md-6">+ @if ($asset->purchase_date){{ Helper::getFormattedDateObject($asset->depreciated_date()->format('Y-m-d'), 'date', false) }}-{{ Carbon::parse($asset->depreciated_date())->diffForHumans() }}+ @else+ {{ trans('general.na_no_purchase_date') }}+ @endif</div></div>@@ -659,10 +666,13 @@</strong></div><div class="col-md-6">+ @if ($asset->purchase_date){{ Helper::getFormattedDateObject($asset->present()->eol_date(), 'date', false) }}-{{ Carbon::parse($asset->present()->eol_date())->diffForHumans() }}-+ @else+ {{ trans('general.na_no_purchase_date') }}+ @endif</div></div>@endif