A free open source IT asset/license management system
Cleaned up seeded data
snipe5b12e6b9cc1c
diff --git a/app/Http/Controllers/Api/OrderItemsController.php b/app/Http/Controllers/Api/OrderItemsController.phpindex 0008a6c92a..6ddb9cc85c 100644--- a/app/Http/Controllers/Api/OrderItemsController.php+++ b/app/Http/Controllers/Api/OrderItemsController.php@@ -101,9 +101,14 @@ class OrderItemsController extends Controllerreturn OrderItem::query()->with(['admin:id,first_name,last_name,username',- 'order:id,order_number,supplier_id,currency,purchase_date,created_by',+ 'order:id,order_number,supplier_id,currency,purchase_date,notes,created_by','order.supplier:id,name','order.admin:id,first_name,last_name,username',+ // action_log carries the receipt filename uploaded via+ // the adjust-quantity modal; surfaced on each Orders-tab+ // row so the file lives with the acquisition record+ // rather than only in the item's Files tab.+ 'actionlog:id,order_item_id,filename,item_id,item_type',])// Orders tab shows purchases only. Corrections / consumption// events (zero or negative-qty OrderItems) belong in thediff --git a/app/Http/Transformers/OrderItemsTransformer.php b/app/Http/Transformers/OrderItemsTransformer.phpindex f600b0de4d..0aeac4cfc0 100644--- a/app/Http/Transformers/OrderItemsTransformer.php+++ b/app/Http/Transformers/OrderItemsTransformer.php@@ -37,6 +37,7 @@ class OrderItemsTransformer'currency' => $order?->currency ? e($order->currency) : null,'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.@@ -47,4 +48,44 @@ class OrderItemsTransformer'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)+ * 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.+ */+ private function transformReceipt(OrderItem $line): ?string+ {+ $log = $line->actionlog;+ if (! $log || ! $log->filename) {+ return null;+ }++ $objectType = self::URL_OBJECT_TYPE[$log->item_type] ?? null;+ if (! $objectType) {+ return null;+ }++ return route('ui.files.show', [+ 'object_type' => $objectType,+ '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',+ ];}diff --git a/app/Models/OrderItem.php b/app/Models/OrderItem.phpindex 90082f6593..e9dd9f9006 100644--- a/app/Models/OrderItem.php+++ b/app/Models/OrderItem.php@@ -5,6 +5,7 @@ namespace App\Models;use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\Relations\BelongsTo;+use Illuminate\Database\Eloquent\Relations\HasOne;use Illuminate\Database\Eloquent\Relations\MorphTo;use Illuminate\Database\Eloquent\SoftDeletes;use Watson\Validating\ValidatingTrait;@@ -76,4 +77,16 @@ class OrderItem extends Model{return $this->belongsTo(User::class, 'created_by');}++ /**+ * The action_log entry that created this OrderItem. Both a `create`+ * observer-write and a `QuantityAdjust` receive their own action_log+ * with `order_item_id` set, so joining on that FK surfaces the file+ * uploaded through the adjust-quantity modal (which attaches its+ * receipt to the action_log, not the OrderItem itself).+ */+ public function actionlog(): HasOne+ {+ return $this->hasOne(Actionlog::class, 'order_item_id')->latest('id');+ }}diff --git a/app/Observers/AccessoryObserver.php b/app/Observers/AccessoryObserver.phpindex 4c6c82bc64..1aa34481e9 100644--- a/app/Observers/AccessoryObserver.php+++ b/app/Observers/AccessoryObserver.php@@ -96,7 +96,9 @@ class AccessoryObserver$logAction->item_type = Accessory::class;$logAction->item_id = $accessory->id;$logAction->created_at = date('Y-m-d H:i:s');- $logAction->created_by = auth()->id();+ // See AssetModelObserver::created for the seeder-friendly+ // auth fallback rationale.+ $logAction->created_by = auth()->id() ?? $accessory->created_by;// Capture the initial on-hand qty so the create log gives auditors// a "started with N units" anchor point. Subsequent QuantityAdjust// logs record deltas, not running totals.diff --git a/app/Observers/AssetModelObserver.php b/app/Observers/AssetModelObserver.phpindex 89b6078811..063f71480c 100644--- a/app/Observers/AssetModelObserver.php+++ b/app/Observers/AssetModelObserver.php@@ -49,7 +49,11 @@ class AssetModelObserver$logAction->item_type = AssetModel::class;$logAction->item_id = $model->id;$logAction->created_at = date('Y-m-d H:i:s');- $logAction->created_by = auth()->id();+ // Fallback to the model's own created_by so seeder / artisan+ // paths (no authenticated user) still attribute the create log+ // to a real user. On web requests auth()->id() is always set,+ // so the fallback never engages there.+ $logAction->created_by = auth()->id() ?? $model->created_by;if ($model->imported) {$logAction->setActionSource('importer');}diff --git a/app/Observers/AssetObserver.php b/app/Observers/AssetObserver.phpindex 67b99a416a..e8b8e8b589 100644--- a/app/Observers/AssetObserver.php+++ b/app/Observers/AssetObserver.php@@ -108,7 +108,9 @@ class AssetObserver$logAction->item_id = $asset->id;$logAction->action_date = date('Y-m-d H:i:s');$logAction->created_at = date('Y-m-d H:i:s');- $logAction->created_by = auth()->id();+ // See AssetModelObserver::created for the seeder-friendly+ // auth fallback rationale.+ $logAction->created_by = auth()->id() ?? $asset->created_by;if ($asset->imported) {$logAction->setActionSource('importer');}diff --git a/app/Observers/ComponentObserver.php b/app/Observers/ComponentObserver.phpindex b21903d80d..13c93d6b45 100644--- a/app/Observers/ComponentObserver.php+++ b/app/Observers/ComponentObserver.php@@ -91,7 +91,9 @@ class ComponentObserver$logAction->item_id = $component->id;$logAction->created_at = date('Y-m-d H:i:s');$logAction->action_date = date('Y-m-d H:i:s');- $logAction->created_by = auth()->id();+ // See AssetModelObserver::created for the seeder-friendly+ // auth fallback rationale.+ $logAction->created_by = auth()->id() ?? $component->created_by;$logAction->quantity = $initialQty;$logAction->order_item_id = $orderItem?->id;if ($component->imported) {diff --git a/app/Observers/ConsumableObserver.php b/app/Observers/ConsumableObserver.phpindex 0a83ef3f7c..f4343a0894 100644--- a/app/Observers/ConsumableObserver.php+++ b/app/Observers/ConsumableObserver.php@@ -87,7 +87,9 @@ class ConsumableObserver$logAction->item_type = Consumable::class;$logAction->item_id = $consumable->id;$logAction->created_at = date('Y-m-d H:i:s');- $logAction->created_by = auth()->id();+ // See AssetModelObserver::created for the seeder-friendly+ // auth fallback rationale.+ $logAction->created_by = auth()->id() ?? $consumable->created_by;$logAction->quantity = $initialQty;$logAction->order_item_id = $orderItem?->id;if ($consumable->imported) {diff --git a/app/Presenters/OrderItemsPresenter.php b/app/Presenters/OrderItemsPresenter.phpindex 09d5d4eeb9..3717091a75 100644--- a/app/Presenters/OrderItemsPresenter.php+++ b/app/Presenters/OrderItemsPresenter.php@@ -153,6 +153,19 @@ class OrderItemsPresenter'title' => trans('general.notes'),'visible' => true,],+ [+ // Receipt file uploaded via the adjust-quantity modal.+ // The transformer returns a URL string (or null) that+ // downloadFormatter renders as a single download button.+ 'field' => 'receipt',+ 'scope' => 'col',+ 'searchable' => false,+ 'sortable' => false,+ 'switchable' => true,+ 'title' => trans('general.file_upload'),+ 'visible' => true,+ 'formatter' => 'downloadFormatter',+ ],];}}diff --git a/database/seeders/AccessorySeeder.php b/database/seeders/AccessorySeeder.phpindex 8d7495f2b7..410d9aac09 100644--- a/database/seeders/AccessorySeeder.php+++ b/database/seeders/AccessorySeeder.php@@ -4,6 +4,7 @@ namespace Database\Seeders;use App\Models\Accessory;use App\Models\AccessoryCheckout;+use App\Models\Actionlog;use App\Models\Location;use App\Models\Supplier;use App\Models\User;@@ -17,6 +18,8 @@ class AccessorySeeder extends Seeder{public function run(){+ // See AssetModelSeeder for the stale-action_log rationale.+ Actionlog::where('item_type', Accessory::class)->delete();Accessory::truncate();DB::table('accessories_checkout')->truncate();diff --git a/database/seeders/AssetModelSeeder.php b/database/seeders/AssetModelSeeder.phpindex b28d6179d5..0d4172229e 100755--- a/database/seeders/AssetModelSeeder.php+++ b/database/seeders/AssetModelSeeder.php@@ -2,6 +2,7 @@namespace Database\Seeders;+use App\Models\Actionlog;use App\Models\AssetModel;use App\Models\User;use Illuminate\Database\Seeder;@@ -12,6 +13,12 @@ class AssetModelSeeder extends Seeder{public function run(){+ // Truncate reuses the same auto-increment IDs on the next+ // seed, so action_logs from prior runs still point at those IDs+ // and show up as stale "create" entries in the History tab.+ // Scoped delete on the leading column of the composite index+ // (item_type, item_id, action_type) — single indexed range op.+ Actionlog::where('item_type', AssetModel::class)->delete();AssetModel::truncate();$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();diff --git a/database/seeders/AssetSeeder.php b/database/seeders/AssetSeeder.phpindex 610e19c142..350aeed795 100644--- a/database/seeders/AssetSeeder.php+++ b/database/seeders/AssetSeeder.php@@ -2,6 +2,7 @@namespace Database\Seeders;+use App\Models\Actionlog;use App\Models\Asset;use App\Models\Location;use App\Models\Supplier;@@ -25,6 +26,8 @@ class AssetSeeder extends Seederpublic function run(){+ // See AssetModelSeeder for the stale-action_log rationale.+ Actionlog::where('item_type', Asset::class)->delete();Asset::truncate();$this->ensureLocationsSeeded();diff --git a/database/seeders/ComponentSeeder.php b/database/seeders/ComponentSeeder.phpindex 8443fb6814..ed5b0f033a 100644--- a/database/seeders/ComponentSeeder.php+++ b/database/seeders/ComponentSeeder.php@@ -2,6 +2,7 @@namespace Database\Seeders;+use App\Models\Actionlog;use App\Models\Asset;use App\Models\Company;use App\Models\Component;@@ -16,6 +17,8 @@ class ComponentSeeder extends Seeder{public function run(){+ // See AssetModelSeeder for the stale-action_log rationale.+ Actionlog::where('item_type', Component::class)->delete();Component::truncate();DB::table('components_assets')->truncate();diff --git a/database/seeders/ConsumableSeeder.php b/database/seeders/ConsumableSeeder.phpindex ba55d626b7..9fb847a0c4 100644--- a/database/seeders/ConsumableSeeder.php+++ b/database/seeders/ConsumableSeeder.php@@ -2,6 +2,7 @@namespace Database\Seeders;+use App\Models\Actionlog;use App\Models\Consumable;use App\Models\Supplier;use App\Models\User;@@ -13,6 +14,8 @@ class ConsumableSeeder extends Seeder{public function run(){+ // See AssetModelSeeder for the stale-action_log rationale.+ Actionlog::where('item_type', Consumable::class)->delete();Consumable::truncate();DB::table('consumables_users')->truncate();diff --git a/resources/views/accessories/view.blade.php b/resources/views/accessories/view.blade.phpindex 643fa490df..d939915961 100644--- a/resources/views/accessories/view.blade.php+++ b/resources/views/accessories/view.blade.php@@ -26,8 +26,8 @@<x-slot:tabnav><x-tabs.checkedout-tab :item="$accessory" count="{{ $accessory->checkouts_count }}" /><x-tabs.files-tab :item="$accessory" count="{{ $accessory->uploads()->count() }}"/>- <x-tabs.history-tab count="{{ $accessory->history()->count() }}" :model="$accessory"/><x-tabs.orders-tab count="{{ $accessory->ordersCount() }}"/>+ <x-tabs.history-tab count="{{ $accessory->history()->count() }}" :model="$accessory"/><x-tabs.upload-tab :item="$accessory"/></x-slot:tabnav>@@ -48,18 +48,18 @@</x-tabs.pane><!-- end assigned tab pane -->- <!-- start history tab pane -->- <x-tabs.pane name="history">- <x-table.history :model="$accessory" :route="route('api.accessories.history', $accessory)" :hide_fields="['serial']"/>- </x-tabs.pane>- <!-- end history tab pane -->-<!-- start orders tab pane --><x-tabs.pane name="orders"><x-table.orders :route="route('api.order-items.index', ['item_type' => \App\Models\Accessory::class, 'item_id' => $accessory->id])"/></x-tabs.pane><!-- end orders tab pane -->+ <!-- start history tab pane -->+ <x-tabs.pane name="history">+ <x-table.history :model="$accessory" :route="route('api.accessories.history', $accessory)" :hide_fields="['serial']"/>+ </x-tabs.pane>+ <!-- end history tab pane -->+<!-- start files tab pane --><x-tabs.pane name="files"><x-table.files object_type="accessories" :object="$accessory"/>diff --git a/resources/views/components/view.blade.php b/resources/views/components/view.blade.phpindex ca5d870201..028583d93b 100644--- a/resources/views/components/view.blade.php+++ b/resources/views/components/view.blade.php@@ -25,8 +25,8 @@/><x-tabs.files-tab :item="$snipe_component" count="{{ $snipe_component->uploads()->count() }}"/>- <x-tabs.history-tab count="{{ $snipe_component->history()->count() }}" :model="$snipe_component"/><x-tabs.orders-tab count="{{ $snipe_component->ordersCount() }}"/>+ <x-tabs.history-tab count="{{ $snipe_component->history()->count() }}" :model="$snipe_component"/><x-tabs.upload-tab :item="$snipe_component"/></x-slot:tabnav>@@ -51,16 +51,16 @@<x-table.files object_type="components" :object="$snipe_component"/></x-tabs.pane>- <!-- start history tab pane -->- <x-tabs.pane name="history">- <x-table.history :model="$snipe_component" :route="route('api.components.history', $snipe_component)"/>- </x-tabs.pane>-<!-- start orders tab pane --><x-tabs.pane name="orders"><x-table.orders :route="route('api.order-items.index', ['item_type' => \App\Models\Component::class, 'item_id' => $snipe_component->id])"/></x-tabs.pane>+ <!-- start history tab pane -->+ <x-tabs.pane name="history">+ <x-table.history :model="$snipe_component" :route="route('api.components.history', $snipe_component)"/>+ </x-tabs.pane>+</x-slot:tabpanes></x-tabs></x-page-column>diff --git a/resources/views/consumables/view.blade.php b/resources/views/consumables/view.blade.phpindex 269a9da131..917bdf136a 100644--- a/resources/views/consumables/view.blade.php+++ b/resources/views/consumables/view.blade.php@@ -29,8 +29,8 @@/><x-tabs.files-tab :item="$consumable" count="{{ $consumable->uploads()->count() }}"/>- <x-tabs.history-tab count="{{ $consumable->history()->count() }}" :model="$consumable"/><x-tabs.orders-tab count="{{ $consumable->ordersCount() }}"/>+ <x-tabs.history-tab count="{{ $consumable->history()->count() }}" :model="$consumable"/><x-tabs.upload-tab :item="$consumable"/></x-slot:tabnav>@@ -50,18 +50,18 @@<x-table.files object_type="consumables" :object="$consumable"/></x-tabs.pane>- <!-- start history tab pane -->- <x-tabs.pane name="history">- <x-table.history :model="$consumable" :route="route('api.consumables.history', $consumable)" :hide_fields="['serial']"/>- </x-tabs.pane>- <!-- end history tab pane -->-<!-- start orders tab pane --><x-tabs.pane name="orders"><x-table.orders :route="route('api.order-items.index', ['item_type' => \App\Models\Consumable::class, 'item_id' => $consumable->id])"/></x-tabs.pane><!-- end orders tab pane -->+ <!-- start history tab pane -->+ <x-tabs.pane name="history">+ <x-table.history :model="$consumable" :route="route('api.consumables.history', $consumable)" :hide_fields="['serial']"/>+ </x-tabs.pane>+ <!-- end history tab pane -->+</x-slot:tabpanes></x-tabs>diff --git a/resources/views/models/view.blade.php b/resources/views/models/view.blade.phpindex fd4b5485e9..b30c1ffdfc 100755--- a/resources/views/models/view.blade.php+++ b/resources/views/models/view.blade.php@@ -28,8 +28,8 @@<x-slot:tabnav><x-tabs.asset-tab count="{{ $model->assets()->AssetsForShow()->count() }}" /><x-tabs.files-tab :item="$model" count="{{ $model->uploads()->count() }}"/>- <x-tabs.history-tab count="{{ $model->history()->count() }}" :model="$model"/><x-tabs.orders-tab count="{{ $model->ordersCount() }}"/>+ <x-tabs.history-tab count="{{ $model->history()->count() }}" :model="$model"/><x-tabs.upload-tab :item="$model"/></x-slot:tabnav>@@ -39,18 +39,30 @@<x-table.assets :route="route('api.assets.index', ['model_id' => $model->id, 'status' => $model->deleted_at!='' ? 'Deleted' : ''])" /></x-tabs.pane>- <!-- start history tab pane -->- <x-tabs.pane name="history">- <x-table.history :model="$model" :route="route('api.models.history', $model)" :hide_fields="['order_number']"/>- </x-tabs.pane>- <!-- end history tab pane -->-<!-- start orders tab pane --><x-tabs.pane name="orders"><x-table.orders :route="route('api.order-items.index', ['asset_model_id' => $model->id])"/></x-tabs.pane><!-- end orders tab pane -->+ <!-- start history tab pane -->+ <x-tabs.pane name="history">+ {{-- AssetModel history is limited to model-level+ events (create / update / delete on the+ model itself). Models aren't checked out+ and don't get files uploaded to them, so+ hide the columns that only carry data for+ per-asset checkout / adjust-quantity flows.+ `item` is redundant since every row is+ this same model. --}}+ <x-table.history+ :model="$model"+ :route="route('api.models.history', $model)"+ :hide_fields="['order_number', 'target', 'item', 'serial', 'file', 'file_download', 'signature_file', 'quantity']"+ />+ </x-tabs.pane>+ <!-- end history tab pane -->+<x-tabs.pane name="files"><x-table.files :object="$model" object_type="models" /></x-tabs.pane>