diff --git a/app/Http/Controllers/API/BrokerApplicationController.php b/app/Http/Controllers/API/BrokerApplicationController.php
index be0a9796..eaf5b2e9 100644
--- a/app/Http/Controllers/API/BrokerApplicationController.php
+++ b/app/Http/Controllers/API/BrokerApplicationController.php
@@ -76,14 +76,15 @@ public function create()
$application = BrokerApplication::create([
- 'account_id' => $this->account->id,
- 'state' => 'draft' //default mysql value is new
+ 'account_id' => $this->account->id,
+ 'state' => 'draft', //default mysql value is new
+ 'is_local' => true
]);
foreach ($documents as $document){
$attachment = new BrokerAttachment([
- 'name' => $document->name,
- 'broker_document_id' => $document->id
+ 'name' => $document->name,
+ 'broker_document_id' => $document->id
]);
$application->broker_attachments()->save($attachment);
}
diff --git a/app/Http/Controllers/API/ResourceController.php b/app/Http/Controllers/API/ResourceController.php
index e1df89e5..8e93b968 100755
--- a/app/Http/Controllers/API/ResourceController.php
+++ b/app/Http/Controllers/API/ResourceController.php
@@ -2,21 +2,13 @@
namespace App\Http\Controllers\API;
-use App\Http\Requests\API\ContractRequest;
-use App\Http\Resources\ContractResource;
use App\Http\Resources\CountryResource;
use App\Http\Resources\CategoryResource;
-use App\Models\Contract;
use App\Models\Country;
use App\Models\Category;
use App\Http\Controllers\Controller;
use App\Http\Resources\QuestionResource;
-use App\Models\Account;
-use App\Models\Application;
-use App\Models\BrokerApplication;
-use App\Models\Client;
use App\Models\Question;
-use Illuminate\Http\Request;
class ResourceController extends Controller
{
@@ -35,44 +27,4 @@ public function faqs()
return QuestionResource::collection(Question::get());//todo investigate do we need all??
}
- public function previewAccountAdmin($id)
- {
- $account = Account::with(['country','profile','clients','applications'])//tormoz etdirer todo fix this
- ->find($id);
-
- return view('admin.preview',[
- 'account' => $account
- ]);
- }
-
- public function previewApplicationAdmin($id){
- $application = Application::with(['account', 'attachments', 'ticket'])->find($id);
- return view('admin.application_preview',[
- 'application' => $application
- ]);
- }
- public function previewBrokerApplicationAdmin($id){
- $application = BrokerApplication::with(['account', 'broker_attachments', 'ticket'])->find($id);
- return view('admin.broker_application_preview',[
- 'application' => $application
- ]);
- }
-
-
- public function createAccountClient($account_id){
- return view('admin.account_client_create',[
- 'account_id' => $account_id
- ]);
- }
-
- public function createClient(Request $request){
- $data = $request->only('firstname', 'lastname', 'email', 'password', 'account_id');
- $data['is_verified'] = false;
- $data['is_suspended'] = false;
- $client = new Client($data);
- $client->save();
- return redirect()->to('/admin/preview/' . $request->account_id . '#users');
- }
-
-
}
diff --git a/app/Http/Controllers/API/TicketController.php b/app/Http/Controllers/API/TicketController.php
index 8f4f8e9a..91af22db 100755
--- a/app/Http/Controllers/API/TicketController.php
+++ b/app/Http/Controllers/API/TicketController.php
@@ -129,6 +129,18 @@ public function createAppTicket(Request $request){
$ticket = new Ticket($request->only('content', 'title','category_id', 'account_id', 'application_id'));
$ticket['status_id'] = 1;
$ticket['client_id'] = $request->account_id;
+ $ticket['last_sender'] = 'admin';
+ $ticket->save();
+ $not_suspended_clients = Client::where('is_suspended', 0)->where('account_id', $request->account_id)->get();
+ Notification::send($not_suspended_clients, new TicketPosted());
+ return redirect(route('chat',['ticket_id' => $ticket->id]));
+ }
+
+ public function createBrokerAppTicket(Request $request){
+ $ticket = new Ticket($request->only('content', 'title','category_id', 'account_id', 'broker_application_id'));
+ $ticket['status_id'] = 1;
+ $ticket['client_id'] = $request->account_id;
+ $ticket['last_sender'] = 'admin';
$ticket->save();
$not_suspended_clients = Client::where('is_suspended', 0)->where('account_id', $request->account_id)->get();
Notification::send($not_suspended_clients, new TicketPosted());
diff --git a/app/Http/Controllers/Admin/AccountCrudController.php b/app/Http/Controllers/Admin/AccountCrudController.php
index a790264c..8e1e5e26 100755
--- a/app/Http/Controllers/Admin/AccountCrudController.php
+++ b/app/Http/Controllers/Admin/AccountCrudController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin;
use App\Http\Requests\AccountRequest;
+use App\Models\Account;
use App\Models\Business;
use App\Models\Company;
use App\Models\Country;
@@ -177,5 +178,22 @@ protected function setupUpdateOperation()
$this->setupCreateOperation();
}
+ public function previewAccountAdmin($id)
+ {
+ $account = Account::with(['country','profile','clients','applications', 'broker_applications'])//tormoz etdirer todo fix this
+ ->find($id);
+
+ return view('admin.preview',[
+ 'account' => $account
+ ]);
+ }
+
+ public function createAccountClient($account_id)
+ {
+ return view('admin.account_client_create',[
+ 'account_id' => $account_id
+ ]);
+ }
+
}
diff --git a/app/Http/Controllers/Admin/ApplicationCrudController.php b/app/Http/Controllers/Admin/ApplicationCrudController.php
index 3ef5b025..ba215b9b 100755
--- a/app/Http/Controllers/Admin/ApplicationCrudController.php
+++ b/app/Http/Controllers/Admin/ApplicationCrudController.php
@@ -92,6 +92,7 @@ function ($value) {
protected function setupListOperation()
{
//$this->crud->addClause('where', 'state', '!=', 'new');
+
$this->crud->addColumns([
[
@@ -133,7 +134,7 @@ protected function setupListOperation()
'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');
}
@@ -159,7 +160,6 @@ public function refine($id){
return redirect()->back();
}
-
public function approveApplication(Request $request){
$application = Application::find($request->id);
$application->state = 'approved';
@@ -174,62 +174,10 @@ public function approveApplication(Request $request){
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')
-// ]
-// ]
-// ]);
-// }
+ public function previewApplicationAdmin($id){
+ $application = Application::with(['account', 'attachments', 'ticket'])->find($id);
+ return view('admin.application_preview',[
+ 'application' => $application
+ ]);
+ }
}
diff --git a/app/Http/Controllers/Admin/BrokerApplicationCrudController.php b/app/Http/Controllers/Admin/BrokerApplicationCrudController.php
index 83d5f8e5..799163da 100644
--- a/app/Http/Controllers/Admin/BrokerApplicationCrudController.php
+++ b/app/Http/Controllers/Admin/BrokerApplicationCrudController.php
@@ -3,9 +3,16 @@
namespace App\Http\Controllers\Admin;
use App\Http\Requests\BrokerApplicationRequest;
+use App\Models\Account;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use App\Models\BrokerApplication;
+use App\Models\Client;
+use App\Notifications\ApplicationApproved;
+use App\Notifications\ApplicationRefined;
+use Carbon\Carbon;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Notification;
/**
* Class BrokerApplicationCrudController
@@ -24,7 +31,7 @@ class BrokerApplicationCrudController extends CrudController
*/
public function setup()
{
- if(!(backpack_user()->hasPermissionTo('applications'))){
+ if(!(backpack_user()->hasPermissionTo('broker-applications'))){
$this->crud->denyAccess(['update']);
}
if(!(backpack_user()->hasRole('Super Admin'))){
@@ -75,6 +82,17 @@ 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);
+ });
+
}
/**
@@ -86,6 +104,7 @@ function ($value) {
protected function setupListOperation()
{
//$this->crud->addClause('where', 'state', '!=', 'new');
+
$this->crud->addColumns([
[
@@ -127,37 +146,50 @@ protected function setupListOperation()
'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']));
- */
+ 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();
}
- /**
- * Define what happens when the Update operation is loaded.
- *
- * @see https://backpackforlaravel.com/docs/crud-operation-update
- * @return void
- */
- protected function setupUpdateOperation()
- {
- $this->setupCreateOperation();
+ 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
+ ]);
}
}
diff --git a/app/Http/Controllers/Admin/ClientCrudController.php b/app/Http/Controllers/Admin/ClientCrudController.php
index a3322df5..bb3548ac 100755
--- a/app/Http/Controllers/Admin/ClientCrudController.php
+++ b/app/Http/Controllers/Admin/ClientCrudController.php
@@ -3,8 +3,10 @@
namespace App\Http\Controllers\Admin;
use App\Http\Requests\ClientRequest;
+use App\Models\Client;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
+use Illuminate\Http\Request;
/**
* Class ClientCrudController
@@ -119,4 +121,13 @@ protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
+
+ public function createClient(Request $request){
+ $data = $request->only('firstname', 'lastname', 'email', 'password', 'account_id');
+ $data['is_verified'] = false;
+ $data['is_suspended'] = false;
+ $client = new Client($data);
+ $client->save();
+ return redirect()->to('/admin/preview/' . $request->account_id . '#users');
+ }
}
diff --git a/app/Http/Resources/BrokerApplicationResource.php b/app/Http/Resources/BrokerApplicationResource.php
index 8bd64e69..9208e633 100644
--- a/app/Http/Resources/BrokerApplicationResource.php
+++ b/app/Http/Resources/BrokerApplicationResource.php
@@ -16,6 +16,7 @@ public function toArray($request)
{
return [
'broker_application_id' => $this->id,
+ 'is_local' => $this->is_local ?? true,
'state' => $this->state,
'accepted_by' => $this->accepted_by,
'accepted_date' => $this->accepted_date,
diff --git a/app/Models/BrokerApplication.php b/app/Models/BrokerApplication.php
index f3f53dcb..85a02359 100644
--- a/app/Models/BrokerApplication.php
+++ b/app/Models/BrokerApplication.php
@@ -21,7 +21,7 @@ class BrokerApplication extends Model
// public $timestamps = false;
// protected $guarded = ['id'];
protected $fillable = [
- 'account_id', 'status','state','accepted_by','approved_by'
+ 'account_id', 'status','state','accepted_by','approved_by', 'ticket_id', 'is_local'
];
// protected $hidden = [];
protected $dates = ['accepted_date','approved_date','created_at','updated_at'];
diff --git a/app/Models/Ticket.php b/app/Models/Ticket.php
index d706bb49..fa0d74cc 100755
--- a/app/Models/Ticket.php
+++ b/app/Models/Ticket.php
@@ -26,7 +26,8 @@ class Ticket extends Model
'content',
'category_id',
'last_sender',
- 'application_id'
+ 'application_id',
+ 'broker_application_id'
];
// protected $hidden = [];
// protected $dates = [];
diff --git a/database/migrations/2023_03_29_205002_add_ticket_to_broker_applications_table.php b/database/migrations/2023_03_29_205002_add_ticket_to_broker_applications_table.php
new file mode 100644
index 00000000..a17bb3dc
--- /dev/null
+++ b/database/migrations/2023_03_29_205002_add_ticket_to_broker_applications_table.php
@@ -0,0 +1,33 @@
+foreignId('ticket_id')->nullable()->constrained();
+ $table->foreignId('is_local')->nullable()->constrained();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('broker_applications', function (Blueprint $table) {
+ //
+ });
+ }
+};
diff --git a/lang/en/app.php b/lang/en/app.php
index b2e0cc0d..b283c97b 100755
--- a/lang/en/app.php
+++ b/lang/en/app.php
@@ -77,6 +77,10 @@
'draft' => "Draft",
],
+ 'broker_application' => [
+ 'list_title' => 'Broker applications',
+ 'is_local' => 'Is local?'
+ ],
'dashboard' => [
'title' => 'Dashboard',
'total_tickets' => "Total tickets",
diff --git a/resources/views/admin/broker_application_preview.blade.php b/resources/views/admin/broker_application_preview.blade.php
index dbce9f9d..106db975 100644
--- a/resources/views/admin/broker_application_preview.blade.php
+++ b/resources/views/admin/broker_application_preview.blade.php
@@ -19,14 +19,14 @@