hasPermissionTo('applications'))){ $this->crud->denyAccess(['update']); } if(!(backpack_user()->hasRole('Super Admin'))){ $this->crud->denyAccess(['delete']); } CRUD::setModel(Application::class); CRUD::setRoute(config('backpack.base.route_prefix') . '/application'); CRUD::setEntityNameStrings('application', trans('app.application.list_title')); Application::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 . '%'); }); } /** * 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'), ] ]); // CRUD::addColumn(['name'=>'country_id', 'type'=>'select','label'=> trans('app.account.country'), 'entity' => 'country' ,'model' => 'App\Model\Country','attribute' => 'name']); $this->crud->addButtonFromModelFunction('line', 'preview_button', 'preview', 'beginning'); } public function accept($id){ $entry = Application::findOrfail($id); $entry->accepted_by = backpack_user()->name; $entry->state = 'accepted'; $entry->accepted_date = Carbon::now(); $entry->save(); \Alert::add('success', 'Success!
Application is accepted')->flash(); return redirect()->back(); } public function refine($id){ $entry = Application::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!
Application is refined')->flash(); return redirect()->back(); } public function approveApplication(Request $request){ $application = Application::find($request->id); $application->state = 'approved'; $application->save(); $account = Account::with('clients')->find($application->account_id); $account->legalization_number = $request->legalization_number; $account->expires_at = $request->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!
Application is approved')->flash(); return redirect()->back(); } /** * Define what happens when the Create operation is loaded. * * @see https://backpackforlaravel.com/docs/crud-operation-create * @return void */ // protected function setupCreateOperation() // { // CRUD::setValidation(ApplicationRequest::class); // $this->crud->addFields([ // [ // SelectMultiple = n-n relationship (with pivot table) // 'label' => trans('app.application.account'), // 'type' => 'custom_select_account', // 'name' => 'account_id', // the method that defines the relationship in your Model // 'entity' => 'account', // the method that defines the relationship in your Model // 'model' => "App\Models\Account", // foreign key model // 'attribute_1' => 'name', // foreign key attribute that is shown to user // 'attribute_2' => 'surname', // ], // [ // 'name' => 'state', // 'label' => trans('app.application.state'), // 'type' => 'select_from_array', // 'options' => [ // 'new' => trans('app.application.new'), // 'applied' => trans('app.application.applied'), // 'refine' => trans('app.application.refine'), // 'approved' => trans('app.application.approved'), // 'archive' => trans('app.application.archived') // ] // ] // ]); // } /** * Define what happens when the Update operation is loaded. * * @see https://backpackforlaravel.com/docs/crud-operation-update * @return void */ // protected function setupUpdateOperation() // { // CRUD::setValidation(ApplicationRequest::class); // $this->crud->addFields([ // [ // 'name' => 'state', // 'label' => 'State', // 'type' => 'select_from_array', // 'options' => [ // 'new' => trans('app.application.new'), // 'applied' => trans('app.application.applied'), // 'refine' => trans('app.application.refine'), // 'approved' => trans('app.application.approved'), // 'archive' => trans('app.application.archived') // ] // ] // ]); // } }