birzha-legalizasia/app/Http/Controllers/Admin/BrokerApplicationCrudContro...

164 lines
5.5 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\BrokerApplicationRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use App\Models\BrokerApplication;
/**
* Class BrokerApplicationCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class BrokerApplicationCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
if(!(backpack_user()->hasPermissionTo('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 . '%');
});
}
/**
* 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');
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
CRUD::setValidation(BrokerApplicationRequest::class);
/**
* Fields can be defined using the fluent syntax or array syntax:
* - CRUD::field('price')->type('number');
* - CRUD::addField(['name' => 'price', 'type' => 'number']));
*/
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
}