@@ -341,68 +341,64 @@ public function show(Asset $asset): View|RedirectResponse
341341 $ this ->authorize ('view ' , $ asset );
342342 $ settings = Setting::getSettings ();
343343
344- if (isset ($ asset )) {
345- $ audit_log = Actionlog::where ('action_type ' , '= ' , 'audit ' )
346- ->where ('item_id ' , '= ' , $ asset ->id )
347- ->where ('item_type ' , '= ' , Asset::class)
348- ->orderBy ('created_at ' , 'DESC ' )->first ();
349-
350- if ($ asset ->location ) {
351- $ use_currency = $ asset ->location ->currency ;
352- } else {
353- if ($ settings ->default_currency != '' ) {
354- $ use_currency = $ settings ->default_currency ;
355- } else {
356- $ use_currency = trans ('general.currency ' );
357- }
358- }
344+ $ audit_log = Actionlog::where ('action_type ' , '= ' , 'audit ' )
345+ ->where ('item_id ' , '= ' , $ asset ->id )
346+ ->where ('item_type ' , '= ' , Asset::class)
347+ ->orderBy ('created_at ' , 'DESC ' )->first ();
359348
360- $ qr_code = (object ) [
361- 'display ' => $ settings ->qr_code == '1 ' ,
362- 'url ' => route ('qr_code/common ' , ['object_type ' => 'hardware ' , 'id ' => $ asset ->id ]),
363- ];
364-
365- $ total_maintenance_cost = $ asset ->maintenances ?->sum('cost ' );
366- $ total_asset_cost = ($ asset ->assignedAssets ()?->AssetsForShow()) ? $ asset ->assignedAssets ()?->AssetsForShow()?->sum('purchase_cost ' ) : 0 ;
367- $ total_license_cost = ($ asset ->licenses ) ? $ asset ->licenses ->sum ('purchase_cost ' ) : 0 ;
368- // accessories.purchase_cost no longer exists; getAccessoryCost()
369- // walks lastOrderDefaults() per attached accessory so the total
370- // reflects each item's last acquisition (with the parent's
371- // default_purchase_cost as fallback).
372- $ total_accessory_cost = $ asset ->getAccessoryCost ();
373- $ total_component_cost = ($ asset ->components ) ? $ asset ->components ->sum ('calculated_purchase_cost ' ) : 0 ;
374-
375- $ total_cost_for_asset = $ asset ->purchase_cost + $ total_maintenance_cost + $ total_asset_cost + $ total_license_cost + $ total_accessory_cost + $ total_component_cost ;
376-
377- $ audit_custom_field_columns = [];
378- if ($ asset ->model && $ asset ->model ->fieldset ) {
379- $ audit_custom_field_columns = $ asset ->model ->fieldset ->fields
380- ->where ('display_audit ' , '1 ' )
381- ->map (fn ($ field ) => [
382- 'field ' => $ field ->db_column ,
383- 'searchable ' => false ,
384- 'sortable ' => false ,
385- 'switchable ' => true ,
386- 'title ' => e ($ field ->name ),
387- 'visible ' => true ,
388- ])
389- ->values ()
390- ->all ();
349+ if ($ asset ->location ) {
350+ $ use_currency = $ asset ->location ->currency ;
351+ } else {
352+ if ($ settings ->default_currency != '' ) {
353+ $ use_currency = $ settings ->default_currency ;
354+ } else {
355+ $ use_currency = trans ('general.currency ' );
391356 }
357+ }
392358
393- return view ('hardware/view ' , compact ('asset ' , 'qr_code ' , 'settings ' ))
394- ->with ('total_maintenance_cost ' , $ total_maintenance_cost )
395- ->with ('total_asset_cost ' , $ total_asset_cost )
396- ->with ('total_license_cost ' , $ total_license_cost )
397- ->with ('total_accessory_cost ' , $ total_accessory_cost )
398- ->with ('total_component_cost ' , $ total_component_cost )
399- ->with ('total_cost_for_asset ' , $ total_cost_for_asset )
400- ->with ('use_currency ' , $ use_currency )
401- ->with ('audit_log ' , $ audit_log )
402- ->with ('audit_custom_field_columns ' , $ audit_custom_field_columns );
359+ $ qr_code = (object ) [
360+ 'display ' => $ settings ->qr_code == '1 ' ,
361+ 'url ' => route ('qr_code/common ' , ['object_type ' => 'hardware ' , 'id ' => $ asset ->id ]),
362+ ];
363+
364+ $ total_maintenance_cost = $ asset ->maintenances ?->sum('cost ' );
365+ $ total_asset_cost = ($ asset ->assignedAssets ()?->AssetsForShow()) ? $ asset ->assignedAssets ()?->AssetsForShow()?->sum('purchase_cost ' ) : 0 ;
366+ $ total_license_cost = ($ asset ->licenses ) ? $ asset ->licenses ->sum ('purchase_cost ' ) : 0 ;
367+ // accessories.purchase_cost no longer exists; getAccessoryCost()
368+ // walks lastOrderDefaults() per attached accessory so the total
369+ // reflects each item's last acquisition (with the parent's
370+ // default_purchase_cost as fallback).
371+ $ total_accessory_cost = $ asset ->getAccessoryCost ();
372+ $ total_component_cost = ($ asset ->components ) ? $ asset ->components ->sum ('calculated_purchase_cost ' ) : 0 ;
373+
374+ $ total_cost_for_asset = $ asset ->purchase_cost + $ total_maintenance_cost + $ total_asset_cost + $ total_license_cost + $ total_accessory_cost + $ total_component_cost ;
375+
376+ $ audit_custom_field_columns = [];
377+ if ($ asset ->model && $ asset ->model ->fieldset ) {
378+ $ audit_custom_field_columns = $ asset ->model ->fieldset ->fields
379+ ->where ('display_audit ' , '1 ' )
380+ ->map (fn ($ field ) => [
381+ 'field ' => $ field ->db_column ,
382+ 'searchable ' => false ,
383+ 'sortable ' => false ,
384+ 'switchable ' => true ,
385+ 'title ' => e ($ field ->name ),
386+ 'visible ' => true ,
387+ ])
388+ ->values ()
389+ ->all ();
403390 }
404391
405- return redirect ()->route ('hardware.index ' )->with ('error ' , trans ('admin/hardware/message.does_not_exist ' ));
392+ return view ('hardware/view ' , compact ('asset ' , 'qr_code ' , 'settings ' ))
393+ ->with ('total_maintenance_cost ' , $ total_maintenance_cost )
394+ ->with ('total_asset_cost ' , $ total_asset_cost )
395+ ->with ('total_license_cost ' , $ total_license_cost )
396+ ->with ('total_accessory_cost ' , $ total_accessory_cost )
397+ ->with ('total_component_cost ' , $ total_component_cost )
398+ ->with ('total_cost_for_asset ' , $ total_cost_for_asset )
399+ ->with ('use_currency ' , $ use_currency )
400+ ->with ('audit_log ' , $ audit_log )
401+ ->with ('audit_custom_field_columns ' , $ audit_custom_field_columns );
406402 }
407403
408404 /**
0 commit comments