Skip to content

Commit

Permalink
add location on retina pallets list
Browse files Browse the repository at this point in the history
  • Loading branch information
inikoo committed Feb 13, 2025
1 parent 8809e22 commit b2e7ac5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 43 deletions.
40 changes: 24 additions & 16 deletions app/Actions/Retina/Fulfilment/Pallet/UI/IndexRetinaPallets.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
class IndexRetinaPallets extends RetinaAction
{
use WithRetinaPalletSubNavigation;

private string $bucket;

protected function getElementGroups(FulfilmentCustomer $fulfilmentCustomer): array
{
return [
Expand Down Expand Up @@ -61,6 +64,8 @@ public function handle(FulfilmentCustomer $fulfilmentCustomer, $prefix = null):

$query = QueryBuilder::for(Pallet::class);
$query->leftJoin('rentals', 'pallets.rental_id', 'rentals.id');
$query->leftJoin('locations', 'pallets.location_id', 'locations.id');

$query->where('fulfilment_customer_id', $fulfilmentCustomer->id);

if ($this->bucket == 'storing') {
Expand All @@ -84,16 +89,16 @@ public function handle(FulfilmentCustomer $fulfilmentCustomer, $prefix = null):
}

return $query->defaultSort('id')
->select('pallets.*', 'rentals.code as rental_code', 'rentals.name as rental_name')
->allowedSorts(['customer_reference', 'reference','state','rental_code'])
->select('pallets.*', 'rentals.code as rental_code', 'rentals.name as rental_name', 'locations.code as location_code')
->allowedSorts(['customer_reference', 'reference', 'state', 'rental_code', 'location_code'])
->allowedFilters([$globalSearch, 'customer_reference'])
->withPaginator($prefix, tableName: request()->route()->getName())
->withQueryString();
}

public function tableStructure(FulfilmentCustomer $fulfilmentCustomer, $prefix = null, $modelOperations = []): Closure
public function tableStructure(FulfilmentCustomer $fulfilmentCustomer, $prefix = null, $modelOperations = [], string $bucket = ''): Closure
{
return function (InertiaTable $table) use ($prefix, $modelOperations, $fulfilmentCustomer) {
return function (InertiaTable $table) use ($prefix, $modelOperations, $fulfilmentCustomer, $bucket) {
if ($prefix) {
$table
->name($prefix)
Expand Down Expand Up @@ -126,6 +131,10 @@ public function tableStructure(FulfilmentCustomer $fulfilmentCustomer, $prefix =
$table->column(key: 'status', label: __('Status'), sortable: true, type: 'icon');
$table->column(key: 'reference', label: __('Id'), canBeHidden: false, sortable: true, searchable: true);
$table->column(key: 'customer_reference', label: __('Reference'), canBeHidden: false, sortable: true, searchable: true);

if ($bucket == 'storing') {
$table->column(key: 'location_code', label: __('Location'), canBeHidden: false, sortable: true, searchable: true);
}
$table->column(key: 'rental_code', label: __('Rent'), canBeHidden: false, sortable: true, searchable: true);
$table->column(key: 'stored_items', label: 'Stored Items', canBeHidden: false, searchable: true);
$table->column(key: 'notes', label: __('Notes'), canBeHidden: false, searchable: true)
Expand All @@ -135,9 +144,8 @@ public function tableStructure(FulfilmentCustomer $fulfilmentCustomer, $prefix =

public function htmlResponse(LengthAwarePaginator $pallets, ActionRequest $request): Response
{
// dd($pallets);
$fulfilmentCustomer = auth()->user()->customer->fulfilmentCustomer;
$subNavigation = $this->getPalletSubNavigation($fulfilmentCustomer);
$fulfilmentCustomer = $this->fulfilmentCustomer;
$subNavigation = $this->getPalletSubNavigation($fulfilmentCustomer);

$actions = [];

Expand All @@ -155,6 +163,7 @@ public function htmlResponse(LengthAwarePaginator $pallets, ActionRequest $reque
]
];
}

return Inertia::render(
'Storage/RetinaPallets',
[
Expand All @@ -163,14 +172,14 @@ public function htmlResponse(LengthAwarePaginator $pallets, ActionRequest $reque
),
'title' => __('pallets'),
'pageHead' => [
'title' => __('pallets'),
'icon' => ['fal', 'fa-pallet'],
'actions' => $actions,
'title' => __('pallets'),
'icon' => ['fal', 'fa-pallet'],
'actions' => $actions,
'subNavigation' => $subNavigation,
],
'data' => RetinaPalletsResource::collection($pallets),
]
)->table($this->tableStructure($this->customer->fulfilmentCustomer, 'pallets'));
)->table($this->tableStructure($this->customer->fulfilmentCustomer, 'pallets', bucket: $this->bucket));
}

public function asController(ActionRequest $request): LengthAwarePaginator
Expand Down Expand Up @@ -214,7 +223,6 @@ public function incidents(ActionRequest $request): LengthAwarePaginator

public function getBreadcrumbs(string $routeName): array
{

return match ($routeName) {
'retina.fulfilment.storage.pallets.index' =>
array_merge(
Expand Down Expand Up @@ -243,7 +251,7 @@ public function getBreadcrumbs(string $routeName): array
'route' => [
'name' => 'retina.fulfilment.storage.pallets.storing_pallets.index',
],
'label' => __('Pallets') .' (' .__('Storing') . ')',
'label' => __('Pallets').' ('.__('Storing').')',
'icon' => 'fal fa-bars',
],

Expand All @@ -260,7 +268,7 @@ public function getBreadcrumbs(string $routeName): array
'route' => [
'name' => 'retina.fulfilment.storage.pallets.returned_pallets.index',
],
'label' => __('Pallets') .' (' .__('Returned') . ')',
'label' => __('Pallets').' ('.__('Returned').')',
'icon' => 'fal fa-bars',
],

Expand All @@ -277,7 +285,7 @@ public function getBreadcrumbs(string $routeName): array
'route' => [
'name' => 'retina.fulfilment.storage.pallets.in_process_pallets.index',
],
'label' => __('Pallets') .' (' .__('In Process') . ')',
'label' => __('Pallets').' ('.__('In Process').')',
'icon' => 'fal fa-bars',
],

Expand All @@ -294,7 +302,7 @@ public function getBreadcrumbs(string $routeName): array
'route' => [
'name' => 'retina.fulfilment.storage.pallets.incidents_pallets.index',
],
'label' => __('Pallets') .' (' .__('Incidents') . ')',
'label' => __('Pallets').' ('.__('Incidents').')',
'icon' => 'fal fa-bars',
],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getPalletSubNavigation(FulfilmentCustomer $fulfilmentCustomer):
'icon' => 'fal fa-align-justify',
'tooltip' => __("All"),
],
"label" => __('all'),
"label" => __('All'),
"route" => [
"name" => "retina.fulfilment.storage.pallets.index",
],
Expand Down
52 changes: 26 additions & 26 deletions app/Http/Resources/Fulfilment/RetinaPalletsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,48 +38,48 @@ class RetinaPalletsResource extends JsonResource
{
public function toArray($request): array
{

return [
'id' => $this->id,
'slug' => $this->slug,
'reference' => $this->reference,
'customer_reference' => $this->customer_reference,
'notes' => (string)$this->notes,
'type_icon' => $this->type->typeIcon()[$this->type->value],
'type' => $this->type,
'rental_code' => $this->rental_code,
'rental_name' => $this->rental_name,
'status' => $this->status,
'status_label' => $this->status->labels()[$this->status->value],
'status_icon' => $this->status->statusIcon()[$this->status->value],
'id' => $this->id,
'slug' => $this->slug,
'reference' => $this->reference,
'customer_reference' => $this->customer_reference,
'notes' => (string)$this->notes,
'type_icon' => $this->type->typeIcon()[$this->type->value],
'type' => $this->type,
'rental_code' => $this->rental_code,
'rental_name' => $this->rental_name,
'location_code' => $this->location_code,
'status' => $this->status,
'status_label' => $this->status->labels()[$this->status->value],
'status_icon' => $this->status->statusIcon()[$this->status->value],

'incident_report_message' => $this->incident_report->message ?? '-',
'stored_items' => $this->storedItems->map(fn (StoredItem $storedItem) => [
'id' => $storedItem->id,
'reference' => $storedItem->reference,
'notes' => $storedItem->notes,
'state' => $storedItem->state,
'state_icon' => $storedItem->state->stateIcon()[$storedItem->state->value],
'quantity' => (int)$storedItem->pivot->quantity,
'incident_report_message' => $this->incident_report->message ?? '-',
'stored_items' => $this->storedItems->map(fn(StoredItem $storedItem) => [
'id' => $storedItem->id,
'reference' => $storedItem->reference,
'notes' => $storedItem->notes,
'state' => $storedItem->state,
'state_icon' => $storedItem->state->stateIcon()[$storedItem->state->value],
'quantity' => (int)$storedItem->pivot->quantity,
]),
'stored_items_quantity' => (int)$this->storedItems()->sum('quantity'),
'updateRoute' => [
'stored_items_quantity' => (int)$this->storedItems()->sum('quantity'),
'updateRoute' => [
'name' => 'retina.models.pallet.update',
'parameters' => $this->id
],
'deleteRoute' => [
'deleteRoute' => [
'name' => 'retina.models.pallet.delete',
'parameters' => $this->id
],
'deleteFromDeliveryRoute' => [
'name' => 'retina.models.pallet-delivery.pallet.delete',
'parameters' => [$this->pallet_delivery_id, $this->id]
],
'deleteFromReturnRoute' => [
'deleteFromReturnRoute' => [
'name' => 'retina.models.pallet-return.pallet.delete',
'parameters' => [$this->pallet_return_id, $this->id]
],
'storeStoredItemRoute' => [
'storeStoredItemRoute' => [
'name' => 'retina.models.pallet.stored-items.update',
'parameters' => [$this->id]
]
Expand Down

0 comments on commit b2e7ac5

Please sign in to comment.