hasPermissionTo('broker-applications'))){ $this->crud->denyAccess(['update']); } if(!(backpack_user()->hasRole('Super Admin'))){ $this->crud->denyAccess(['delete']); } CRUD::setModel(BrokerApplication::class); CRUD::setRoute(config('backpack.base.route_prefix') . '/broker-application'); CRUD::setEntityNameStrings('broker application', 'broker applications'); BrokerApplication::updating(function($entry) { $entry->modified_by = backpack_user()->name; }); $this->crud->addClause('where', 'state', '!=', 'Draft'); $this->crud->addFilter([ 'name' => 'state', 'type' => 'dropdown', 'label' => trans('app.application.state') ], [ 'new' => trans('app.application.new'), 'accepted' => trans('app.application.accepted'), 'refine' => trans('app.application.refine'), 'approved' => trans('app.application.approved'), 'archive' => trans('app.application.archived') ], function ($value) { $this->crud->addClause('where', 'state', $value); }); $this->crud->addFilter([ 'type' => 'date_range', 'name' => 'from_to', 'label' => trans('app.application.date_filter'), ], false, function ($value) { $dates = json_decode($value); $this->crud->addClause('where', 'created_at', '>=', $dates->from); $this->crud->addClause('where', 'created_at', '<=', $dates->to . ' 23:59:59'); }); $this->crud->addFilter([ 'type' => 'text', 'name' => 'accepted_by', 'label' => trans('app.last_updates.accepted_by'), ], false, function ($value) { $this->crud->addClause('where', 'accepted_by', 'LIKE', '%' . $value . '%'); }); $this->crud->addFilter([ 'name' => 'is_local', 'type' => 'dropdown', 'label' => trans('app.broker_application.is_local') ], [ 0 => trans('app.no'), 1 => trans('app.yes') ], function ($value) { $this->crud->addClause('where', 'is_local', $value); }); } /** * Define what happens when the List operation is loaded. * * @see https://backpackforlaravel.com/docs/crud-operation-list-entries * @return void */ protected function setupListOperation() { //$this->crud->addClause('where', 'state', '!=', 'new'); $this->crud->addColumns([ [ 'label' => trans('app.application.name'), 'type' => 'select', 'name' => 'account_type', 'entity' => 'account', 'model' => "App\Models\Account", 'attribute' => 'type_and_name', ], [ 'label' => trans('app.application.leg_number'), 'type' => 'select', 'name' => 'account_legnumber', 'entity' => 'account', 'model' => "App\Models\Account", 'attribute' => 'legalization_number', ], [ 'label' => trans('app.application.expires_at'), 'type' => 'select', 'name' => 'account_exp_date', 'entity' => 'account', 'model' => "App\Models\Account", 'attribute' => 'expires_at', ], [ 'name' => 'state', 'label' => trans('app.application.state'), 'type' => 'badge', ], [ 'name' => 'accepted_by', 'label' => trans('app.last_updates.accepted_by'), 'type' => 'text', ], [ 'name' => 'created_at', 'label' => trans('app.application.created_at'), ] ]); $this->crud->addButtonFromModelFunction('line', 'preview_button', 'preview', 'beginning'); } public function accept($id){ $entry = BrokerApplication::findOrfail($id); $entry->accepted_by = backpack_user()->name; $entry->state = 'accepted'; $entry->accepted_date = Carbon::now(); $entry->save(); \Alert::add('success', 'Success!
Broker application is accepted')->flash(); return redirect()->back(); } public function refine($id){ $entry = BrokerApplication::findOrfail($id); $entry->state = 'refine'; $entry->refine_note = request()->get('note'); $entry->save(); $account = Account::with('clients')->find($entry->account_id); $not_suspended_clients = Client::where('is_suspended', 0)->where('account_id', $account->id)->get(); Notification::send($not_suspended_clients, new ApplicationRefined()); \Alert::add('success', 'Success!
Broker application is refined')->flash(); return redirect()->back(); } public function approveApplication(Request $request){ $application = BrokerApplication::find($request->id); $application->state = 'approved'; $application->save(); $account = Account::with('clients')->find($application->account_id); $account->broker_number = $request->broker_number; $account->broker_expires_at = $request->broker_expires_at; $account->save(); $not_suspended_clients = Client::where('is_suspended', 0)->where('account_id', $account->id)->get(); Notification::send($not_suspended_clients, new ApplicationApproved()); \Alert::add('success', 'Success!
Broker application is approved')->flash(); return redirect()->back(); } public function previewBrokerApplicationAdmin($id){ $application = BrokerApplication::with(['account', 'broker_attachments', 'ticket'])->find($id); return view('admin.broker_application_preview',[ 'application' => $application ]); } }