@extends('layouts.app') @section('title', __('Stock Request')) @section('content')

@lang('Stock Request') @lang('New Stock Request')


@php use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; // Get the logged-in user ID $userId = Auth::id(); // Get the user's business_id $businessId = DB::table('users')->where('id', $userId)->value('business_id'); // Get location permissions like "location.1", "location.2", etc. $locationPermissions = DB::table('model_has_permissions') ->join('permissions', 'model_has_permissions.permission_id', '=', 'permissions.id') ->where('model_has_permissions.model_id', $userId) ->where('permissions.name', 'like', 'location.%') ->pluck('permissions.name'); // Extract numeric location IDs and exclude ID 1 $assignedLocationIds = $locationPermissions->map(function ($name) { return (int) str_replace('location.', '', $name); })->filter(function ($id) { return $id !== 1; })->values()->toArray(); // Assigned locations for "Request From" (user-permitted locations) $business_locations_assigned = DB::table('business_locations') ->where('business_id', $businessId) ->whereIn('id', $assignedLocationIds) ->where('id', '<>', 1) ->pluck('name', 'id') ->toArray(); // All other locations (excluding assigned ones) $business_locations_others = DB::table('business_locations') ->where('business_id', $businessId) ->whereNotIn('id', $assignedLocationIds) ->where('id', '<>', 1) ->pluck('name', 'id') ->toArray(); @endphp
{!! Form::label('location_id', __('Request From') . ':') !!} {!! Form::select('request_from', $business_locations_assigned, null, [ 'class' => 'form-control select2', 'style' => 'width:100%', 'id' => 'request_location', 'placeholder' => __('Select Request From') ]) !!}
{!! Form::label('location_id', __('Request To') . ':') !!} {!! Form::select('location_id', $business_locations_others, null, [ 'class' => 'form-control select2', 'style' => 'width:100%', 'id' => 'product_list_filter_location_id', 'placeholder' => __('Select Request To') ]) !!}
{!! Form::label('category_id', __('product.category') . ':') !!} {!! Form::select('category_id', $categories, null, [ 'class' => 'form-control select2', 'style' => 'width:100%', 'id' => 'product_list_filter_category_id', 'placeholder' => __('lang_v1.all') ]) !!}
Stock Request Records

@lang('Products')

@include('stockrequest.partials.product_list', ['products' => collect()])
@endsection