Skip to content

Commit 2a49136

Browse files
Sort storage locations, allow to add a storage location when creating a material, link materials from organizations
1 parent 953343c commit 2a49136

File tree

6 files changed

+61
-25
lines changed

6 files changed

+61
-25
lines changed

app/Http/Controllers/OrganizationController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function index(OrganizationFilterRequest $request): View
2929
'documents',
3030
'events',
3131
'eventSeries',
32+
'materials',
3233
])
3334
->paginate(10),
3435
]);

app/Models/Organization.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*
3838
* @property Collection|Event[] $events {@see self::events()}
3939
* @property Collection|EventSeries[] $eventSeries {@see self::eventSeries()}
40+
* @property Collection|Material[] $materials {@see self::materials()}
4041
*/
4142
class Organization extends Model
4243
{
@@ -83,6 +84,11 @@ public function eventSeries(): HasMany
8384
return $this->hasMany(EventSeries::class);
8485
}
8586

87+
public function materials(): HasMany
88+
{
89+
return $this->hasMany(Material::class);
90+
}
91+
8692
public function scopeEvent(Builder $query, int|string $eventId): Builder
8793
{
8894
return $this->scopeRelation($query, $eventId, 'events', fn (Builder $q) => $q->where('event_id', '=', $eventId));

app/Models/StorageLocation.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ public static function allowedFilters(): array
177177
];
178178
}
179179

180+
/**
181+
* @return array<int, string>
182+
*/
183+
public static function defaultSorts(): array
184+
{
185+
return [
186+
'name',
187+
];
188+
}
189+
180190
/**
181191
* @return array<string, string>
182192
*/

resources/views/materials/material_form.blade.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,32 +73,32 @@
7373
</x-bs::form.field>
7474
</x-bs::list.item>
7575
@endforeach
76-
<x-bs::list.item>
77-
<div class="small mb-1">{{ __('To add another storage location, select one.') }}</div>
78-
@livewire('storage-locations.select-storage-location', [
79-
'id' => 'storage-location-new',
80-
'name' => 'storage_locations[new][storage_location_id]',
81-
'selectedStorageLocation' => null,
82-
], key('storage-location-new'))
83-
<div class="row mt-3">
84-
<div class="col-12 col-xxl-6">
85-
<x-bs::form.field name="storage_locations[new][material_status]"
86-
type="select" :options="\App\Enums\MaterialStatus::toOptions()->prepend(__('select status'), '')">
87-
{{ __('Status') }}
88-
</x-bs::form.field>
89-
</div>
90-
<div class="col-12 col-xxl-6">
91-
<x-bs::form.field name="storage_locations[new][stock]"
92-
type="number" min="1" step="1">
93-
{{ __('Stock') }}
94-
</x-bs::form.field>
95-
</div>
96-
</div>
97-
<x-bs::form.field name="storage_locations[new][remarks]" type="textarea">
98-
{{ __('Remarks') }}
99-
</x-bs::form.field>
100-
</x-bs::list.item>
10176
@endisset
77+
<x-bs::list.item>
78+
<div class="small mb-1">{{ __('To add another storage location, select one.') }}</div>
79+
@livewire('storage-locations.select-storage-location', [
80+
'id' => 'storage-location-new',
81+
'name' => 'storage_locations[new][storage_location_id]',
82+
'selectedStorageLocation' => null,
83+
], key('storage-location-new'))
84+
<div class="row mt-3">
85+
<div class="col-12 col-xxl-6">
86+
<x-bs::form.field name="storage_locations[new][material_status]"
87+
type="select" :options="\App\Enums\MaterialStatus::toOptions()->prepend(__('select status'), '')">
88+
{{ __('Status') }}
89+
</x-bs::form.field>
90+
</div>
91+
<div class="col-12 col-xxl-6">
92+
<x-bs::form.field name="storage_locations[new][stock]"
93+
type="number" min="1" step="1">
94+
{{ __('Stock') }}
95+
</x-bs::form.field>
96+
</div>
97+
</div>
98+
<x-bs::form.field name="storage_locations[new][remarks]" type="textarea">
99+
{{ __('Remarks') }}
100+
</x-bs::form.field>
101+
</x-bs::list.item>
102102
</x-bs::list>
103103
</div>
104104
</div>

resources/views/organizations/organization_index.blade.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@
134134
<x-bs::badge>{{ formatInt($organization->documents_count) }}</x-bs::badge>
135135
</x-slot:end>
136136
</x-bs::list.item>
137+
<x-bs::list.item>
138+
<span>
139+
<i class="fa fa-fw fa-toolbox"></i>
140+
@can('viewAny', \App\Models\Material::class)
141+
<a href="{{ route('materials.index', ['filter[organization_id]' => $organization->id]) }}" target="_blank">{{ __('Materials') }}</a>
142+
@else
143+
{{ __('Materials') }}
144+
@endcan
145+
</span>
146+
<x-slot:end>
147+
<x-bs::badge>{{ formatInt($organization->materials_count) }}</x-bs::badge>
148+
</x-slot:end>
149+
</x-bs::list.item>
137150
<x-bs::list.item>
138151
<span>
139152
<i class="fa fa-fw fa-calendar-days"></i>

resources/views/organizations/shared/organization_details.blade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
</div>
4949
</x-bs::list.item>
5050
@endisset
51+
@can('viewAny', \App\Models\Material::class)
52+
<x-bs::list.item>
53+
<span class="me-3"><i class="fa fa-fw fa-toolbox"></i></span>
54+
<a href="{{ route('materials.index', ['filter[organization_id]' => $organization->id]) }}">{{ __('Materials') }}</a>
55+
</x-bs::list.item>
56+
@endcan
5157
@can('viewAny', \App\Models\Event::class)
5258
<x-bs::list.item>
5359
<span class="me-3"><i class="fa fa-fw fa-calendar-days"></i></span>

0 commit comments

Comments
 (0)