From bd212b31088c9269f8f20b39451bd58f243179c2 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 19 Apr 2023 16:35:06 -0700 Subject: [PATCH] adds component costs to asset view --- app/Models/Asset.php | 8 +++++++- resources/lang/en/admin/hardware/table.php | 1 + resources/views/hardware/view.blade.php | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index a5211e8001..8c92f8c78e 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -909,7 +909,13 @@ class Asset extends Depreciable return false; } - + public function getComponentCost(){ + $cost = 0; + foreach($this->components as $component) { + $cost += $component->pivot->assigned_qty*$component->purchase_cost; + } + return $cost; + } /** * ----------------------------------------------- diff --git a/resources/lang/en/admin/hardware/table.php b/resources/lang/en/admin/hardware/table.php index 6166ba8045..10629fd22c 100644 --- a/resources/lang/en/admin/hardware/table.php +++ b/resources/lang/en/admin/hardware/table.php @@ -8,6 +8,7 @@ return [ 'change' => 'In/Out', 'checkout_date' => 'Checkout Date', 'checkoutto' => 'Checked Out', + 'components_cost' => 'Total Components Cost', 'current_value' => 'Current Value', 'diff' => 'Diff', 'dl_csv' => 'Download CSV', diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index ccd3f86536..ce3a040c82 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -530,6 +530,25 @@ @endif + @if(($asset->components->count() > 0) && ($asset->purchase_cost)) +
+
+ + {{ trans('admin/hardware/table.components_cost') }} + +
+
+ @if (($asset->id) && ($asset->location)) + {{ $asset->location->currency }} + @elseif (($asset->id) && ($asset->location)) + {{ $asset->location->currency }} + @else + {{ $snipeSettings->default_currency }} + @endif + {{Helper::formatCurrencyOutput($asset->getComponentCost())}} +
+
+ @endif @if (($asset->model) && ($asset->depreciation) && ($asset->purchase_date))