A free open source IT asset/license management system
Set admin
snipe6b2e33bccda9
diff --git a/app/Http/Transformers/OrderItemsTransformer.php b/app/Http/Transformers/OrderItemsTransformer.phpindex 0aeac4cfc0..65445302ba 100644--- a/app/Http/Transformers/OrderItemsTransformer.php+++ b/app/Http/Transformers/OrderItemsTransformer.php@@ -3,6 +3,7 @@namespace App\Http\Transformers;use App\Helpers\Helper;+use App\Http\Controllers\Controller;use App\Models\OrderItem;use Illuminate\Database\Eloquent\Collection;@@ -23,6 +24,10 @@ class OrderItemsTransformer$order = $line->order;$qty = (int) $line->qty;$price = $line->price !== null ? (float) $line->price : null;+ // Prefer the OrderItem's own creator (per-line authorship).+ // Falls back to the parent Order's created_by so+ // rows with a null order_items.created_by still show a name.+ $admin = $line->admin ?? $order?->admin;return ['id' => (int) $line->id,@@ -38,24 +43,21 @@ class OrderItemsTransformer'total_cost' => $price !== null ? Helper::formatCurrencyOutput($qty * $price) : null,'notes' => $order?->notes ? Helper::parseEscapedMarkedownInline($order->notes) : null,'receipt' => $this->transformReceipt($line),- // Prefer the OrderItem's own creator (per-line authorship).- // Falls back to the parent Order's created_by so pre-146000- // rows with a null order_items.created_by still show a name.- 'created_by' => ($line->admin ?? $order?->admin) ? [- 'id' => (int) ($line->admin?->id ?? $order->admin->id),- 'name' => e(($line->admin ?? $order->admin)->display_name),+ 'created_by' => $admin ? [+ 'id' => (int) $admin->id,+ 'name' => e($admin->display_name),] : null,'created_at' => Helper::getFormattedDateObject($line->created_at, 'datetime'),];}/**- * Surface the receipt uploaded via the adjust-quantity modal. The- * file is attached to the action_log (not to the OrderItem itself)+ * Surface the receipt/whatever file uploaded via the adjust-quantity modal.+ * The file is attached to the action_log (not to the OrderItem itself)* so this walks the OrderItem's actionlog relation and builds a- * download URL against the item's private_uploads path. Returns- * null when no file was uploaded for the acquisition. The Orders- * tab's presenter renders the URL string via downloadFormatter.+ * download URL using Controller::$map_class_url_segment. Returns null+ * when no file was uploaded or when the item's class is not+ * registered for URL-segment lookup.*/private function transformReceipt(OrderItem $line): ?string{@@ -64,28 +66,15 @@ class OrderItemsTransformerreturn null;}- $objectType = self::URL_OBJECT_TYPE[$log->item_type] ?? null;- if (! $objectType) {+ $segment = Controller::getMapClassUrlSegment()[$log->item_type] ?? null;+ if ($segment === null) {return null;}return route('ui.files.show', [- 'object_type' => $objectType,+ 'object_type' => $segment,'id' => $log->item_id,'file_id' => $log->id,]);}-- /**- * Map an inventory model class to the URL segment the- * `ui.files.show` route expects. Not every model in- * Controller::$map_object_type participates in Orders, so this is- * a narrow inversion of the parent map.- */- private const URL_OBJECT_TYPE = [- \App\Models\Accessory::class => 'accessories',- \App\Models\Consumable::class => 'consumables',- \App\Models\Component::class => 'components',- \App\Models\Asset::class => 'hardware',- ];}