wip on loan orders
This commit is contained in:
@@ -95,6 +95,27 @@ class LoanOrder extends Resource
|
|||||||
return __('Loan order');
|
return __('Loan order');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build an "index" query for the given resource.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public static function indexQuery(NovaRequest $request, $query)
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
if ($user->isAdmin()) {
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->isOperator()) {
|
||||||
|
return $query->whereIn('branch_id', $user->branches()->pluck('id'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query->where('user_id', $request->user()->id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the fields for index.
|
* Get the fields for index.
|
||||||
*/
|
*/
|
||||||
@@ -119,16 +140,6 @@ class LoanOrder extends Resource
|
|||||||
return [
|
return [
|
||||||
ID::make()->sortable(),
|
ID::make()->sortable(),
|
||||||
|
|
||||||
Badge::make(__('Status'), 'status')
|
|
||||||
->map(OrderRepo::statusClasses())
|
|
||||||
->addTypes([
|
|
||||||
'primary' => 'dark:bg-gray-900 bg-gray-600 text-white',
|
|
||||||
])
|
|
||||||
->labels(OrderRepo::statusValues())
|
|
||||||
->withIcons()
|
|
||||||
->icons(OrderRepo::statusIcons())
|
|
||||||
->sortable(),
|
|
||||||
|
|
||||||
Select::make(__('Status'), 'status')
|
Select::make(__('Status'), 'status')
|
||||||
->displayUsingLabels()
|
->displayUsingLabels()
|
||||||
->searchable()
|
->searchable()
|
||||||
@@ -136,7 +147,7 @@ class LoanOrder extends Resource
|
|||||||
->default(OrderRepo::defaultStatus())
|
->default(OrderRepo::defaultStatus())
|
||||||
->fullWidth()
|
->fullWidth()
|
||||||
->rules('required')
|
->rules('required')
|
||||||
->sortable(),
|
->canSeeWhen('systemUser', $this),
|
||||||
|
|
||||||
new Panel(__('Loan'), [
|
new Panel(__('Loan'), [
|
||||||
Select::make(__('Loan type'), 'loan_type')
|
Select::make(__('Loan type'), 'loan_type')
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
// use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
use App\Models\Branch\Branch;
|
use App\Models\Branch\Branch;
|
||||||
use App\Models\Order\Loan\LoanOrder;
|
use App\Models\Order\Loan\LoanOrder;
|
||||||
use App\Models\Order\Loan\LoanType;
|
use App\Models\Order\Loan\LoanType;
|
||||||
@@ -43,6 +43,8 @@ class AuthServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
//
|
Gate::define('isMe', fn ($user) => $user->isMe());
|
||||||
|
Gate::define('isAdmin', fn ($user) => $user->isAdmin());
|
||||||
|
Gate::define('systemUser', fn ($user) => $user->isAdmin() || $user->isOperator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user