diff --git a/app/Http/Controllers/API/AccountController.php b/app/Http/Controllers/API/AccountController.php index b950551a..10fb0953 100644 --- a/app/Http/Controllers/API/AccountController.php +++ b/app/Http/Controllers/API/AccountController.php @@ -17,7 +17,7 @@ public function __construct() { $this->middleware(function ($request, $next) { - $this->account = Auth::user() + $this->account = auth()->user() ->account() ->with('profile') ->first(); diff --git a/app/Http/Controllers/API/ApplicationController.php b/app/Http/Controllers/API/ApplicationController.php index 16794e83..dcebd597 100644 --- a/app/Http/Controllers/API/ApplicationController.php +++ b/app/Http/Controllers/API/ApplicationController.php @@ -28,6 +28,7 @@ public function __construct() }); } + /** * Create new Legalization Application * @return ApplicationResource|\Illuminate\Http\Response @@ -129,15 +130,6 @@ public function apply() if( $app ) { -// $unAttachedDocumentsCount = $app->attachments->whereNull('file')->count(); -// -// if($unAttachedDocumentsCount >0) -// { -// return response([ -// 'success' => false, -// 'message' => trans('app.application.required_docs_message') -// ],422); -// } $app->state = 'new'; $app->save(); @@ -169,18 +161,12 @@ public function upload(DocumentUploadRequest $request,$attachment_id) $uploadedFile = $request->file('file'); -// Log::info($uploadedFile->getSize()); if($attachment->document->max_size != 0 && $uploadedFile->getSize() > $attachment->document->max_size * 1024){//max size in kilobytes return response()->json(['success' => false, 'message' =>trans('app.application.upload_max_size')],422); } -// if($attachment->file){ -// //todo delete or replace old file -//// Stor -// } - $filename = Str::snake($attachment->name).'.'.$uploadedFile->getClientOriginalExtension(); $directory = 'documents/'.Carbon::today()->year.'/'.$this->account->id; @@ -201,7 +187,8 @@ public function upload(DocumentUploadRequest $request,$attachment_id) //todo make attachment relation } - public function downloadQuestionaire(){ + public function downloadQuestionaire() + { $headers = [ "Content-type"=>"text/html", "Content-Disposition"=>"attachment;Filename=myGeneratefile.doc" diff --git a/app/Http/Controllers/API/BrokerApplicationController.php b/app/Http/Controllers/API/BrokerApplicationController.php new file mode 100644 index 00000000..162433b0 --- /dev/null +++ b/app/Http/Controllers/API/BrokerApplicationController.php @@ -0,0 +1,189 @@ +middleware(function ($request, $next) { + $this->account = auth()->guard('api')->user() + ->account() + ->with('profile') + ->with('broker_applications') + ->first(); + return $next($request); + }); + } + + /** + * Create new Legalization Application + * @return BrokerApplicationResource|\Illuminate\Http\Response + */ + public function create() + { + //validate if profile is filled + if(is_null($this->account) || is_null($this->account->profile)) + { + return response([ + 'success' => false, + 'message' => trans('app.application.fill_profile_message'), + ],422); + } + //validate legalization number exists + elseif(!$this->account->can_apply_broker && !$this->account->can_extend_broker){ + $month = Config::get('settings.legalization_extend') ?? 1; + return response([ + 'success' => false, + 'message' => trans('app.application.expire_message',['one'=>$month]) + ],422); + } + + //delete old application??? Should we replace it??? + if($app = $this->account->last_broker_application()) + { + if($app->state != 'approved') + return BrokerApplicationResource::make($app); + else{ + $app->state = 'archive'; + $app->save(); + } + } + + //upload etmeli dokumentlaryn spisogy + $documents = BrokerDocument::where($this->account->type,true)->get(); + + if($documents->count() == 0) + { + return response([ + 'success' => false, + 'message' => trans('application.list_not_found') + ],404); + } + + + $application = BrokerApplication::create([ + 'account_id' => $this->account->id, + 'state' => 'draft' //default mysql value is new + ]); + + foreach ($documents as $document){ + $attachment = new BrokerAttachment([ + 'name' => $document->name, + 'document_id' => $document->id + ]); + $application->broker_attachments()->save($attachment); + } + + return BrokerApplicationResource::make($application); + + } + + + public function get() + { + $application = $this->account + ->broker_applications() + ->latest() + ->with('broker_attachments')->first(); + + if($application){ + return BrokerApplicationResource::make($application); + } + + return response()->json(['success' => false, 'message' => 'Not Found'], 404); + + } + + public function apply() + { + $app = $this->account + ->broker_applications() + ->whereIn('state',['draft','refine']) + ->with('broker_attachments') + ->latest() + ->first(); + + if( $app ) + { + $app->state = 'new'; + $app->save(); + + //todo send email to operators + return response([ + 'success' => true, + 'message' => trans('app.application.app_success_message') + ]); + + } + + return response([ + 'success' => false, + 'message' => trans('app.application.app_error_message') + ],400); + + } + + public function upload(DocumentUploadRequest $request,$attachment_id) + { + + $attachment = BrokerAttachment::with(['broker_application','document'])->find($attachment_id); + + if(!$attachment || !$attachment->broker_application || $attachment->broker_application->account_id != $this->account->id ){ + + return response()->json(['success' => false, 'message' =>'Bad request'],400); + } + + $uploadedFile = $request->file('file'); + + + if($attachment->document->max_size != 0 + && $uploadedFile->getSize() > $attachment->document->max_size * 1024){//max size in kilobytes + return response()->json(['success' => false, 'message' =>trans('app.application.upload_max_size')],422); + } + + $filename = Str::snake($attachment->name).'.'.$uploadedFile->getClientOriginalExtension(); + + $directory = 'documents/'.Carbon::today()->year.'/'.$this->account->id; + + $path = $uploadedFile->storePubliclyAs($directory,$filename); + + if(!$path){ + return response()->json(['success' => false, 'message' =>trans('app.application.upload_failure')],400); + } + + $attachment->file = $directory.'/'.$filename; + $attachment->size = number_format($uploadedFile->getSize()/1024, 2, '.', ''); + $attachment->type = $uploadedFile->getClientOriginalExtension(); + $attachment->save(); + + return response()->json(['success' => true, 'message' =>trans('app.app.application.upload_success')]); + + //todo make attachment relation + } + + public function downloadQuestionaire() + { + $headers = [ + "Content-type"=>"text/html", + "Content-Disposition"=>"attachment;Filename=myGeneratefile.doc" + ]; + + $content = view('oprosniki.'.$this->account->type,$this->account->profile)->render(); + + return \Response::make($content,200, $headers); + } +} diff --git a/app/Http/Controllers/API/ContractController.php b/app/Http/Controllers/API/ContractController.php index f05970e4..ee7060e8 100644 --- a/app/Http/Controllers/API/ContractController.php +++ b/app/Http/Controllers/API/ContractController.php @@ -22,31 +22,32 @@ public function contract(ContractRequest $request){ } public function import(Request $request){ - foreach($request->all() as $item){ - $contract['foreign_ID'] = $item['ID']; - $contract['InputNumber'] = $item['InputNumber']; - $contract['InputDate'] = $item['InputDate']; - $contract['RegDate'] = $item['RegDate']; - $contract['MarkerSpec'] = $item['MarkerSpec']; - $contract['Workflow_ID'] = $item['Workflow_ID']; - $contract['Note'] = $item['Note']; - $contract['Remark'] = $item['Remark']; + Log::info($request->all()); + // foreach($request->all() as $item){ + // $contract['foreign_ID'] = $item['ID']; + // $contract['InputNumber'] = $item['InputNumber']; + // $contract['InputDate'] = $item['InputDate']; + // $contract['RegDate'] = $item['RegDate']; + // $contract['MarkerSpec'] = $item['MarkerSpec']; + // $contract['Workflow_ID'] = $item['Workflow_ID']; + // $contract['Note'] = $item['Note']; + // $contract['Remark'] = $item['Remark']; - $record = Contract::where('foreign_ID', $contract['foreign_ID'])->first(); - if($record != null){ - $record['InputNumber'] = $item['InputNumber']; - $record['InputDate'] = $item['InputDate']; - $record['RegDate'] = $item['RegDate']; - $record['MarkerSpec'] = $item['MarkerSpec']; - $record['Workflow_ID'] = $item['Workflow_ID']; - $record['Note'] = $item['Note']; - $record['Remark'] = $item['Remark']; - $record->save(); - } - else{ - Contract::create($contract); - } - } + // $record = Contract::where('foreign_ID', $contract['foreign_ID'])->first(); + // if($record != null){ + // $record['InputNumber'] = $item['InputNumber']; + // $record['InputDate'] = $item['InputDate']; + // $record['RegDate'] = $item['RegDate']; + // $record['MarkerSpec'] = $item['MarkerSpec']; + // $record['Workflow_ID'] = $item['Workflow_ID']; + // $record['Note'] = $item['Note']; + // $record['Remark'] = $item['Remark']; + // $record->save(); + // } + // else{ + // Contract::create($contract); + // } + // } return 'ok'; } diff --git a/app/Http/Controllers/API/ResourceController.php b/app/Http/Controllers/API/ResourceController.php index 657277c5..e1df89e5 100755 --- a/app/Http/Controllers/API/ResourceController.php +++ b/app/Http/Controllers/API/ResourceController.php @@ -13,6 +13,7 @@ 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; @@ -46,11 +47,16 @@ public function previewAccountAdmin($id) public function previewApplicationAdmin($id){ $application = Application::with(['account', 'attachments', 'ticket'])->find($id); - //dd($application->tickets); 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){ diff --git a/app/Http/Controllers/Admin/ApplicationCrudController.php b/app/Http/Controllers/Admin/ApplicationCrudController.php index 0cd3457c..3ef5b025 100755 --- a/app/Http/Controllers/Admin/ApplicationCrudController.php +++ b/app/Http/Controllers/Admin/ApplicationCrudController.php @@ -135,7 +135,6 @@ protected function setupListOperation() ]); // 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'); -// $this->crud->addButtonFromModelFunction('line', 'accept_button', 'accept', 'beginning'); } public function accept($id){ diff --git a/app/Http/Controllers/Admin/BrokerApplicationCrudController.php b/app/Http/Controllers/Admin/BrokerApplicationCrudController.php new file mode 100644 index 00000000..83d5f8e5 --- /dev/null +++ b/app/Http/Controllers/Admin/BrokerApplicationCrudController.php @@ -0,0 +1,163 @@ +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(); + } +} diff --git a/app/Http/Controllers/Admin/BrokerAttachmentCrudController.php b/app/Http/Controllers/Admin/BrokerAttachmentCrudController.php new file mode 100644 index 00000000..d33a96e1 --- /dev/null +++ b/app/Http/Controllers/Admin/BrokerAttachmentCrudController.php @@ -0,0 +1,119 @@ +crud->setFromDb(); + /** + * Columns can be defined using the fluent syntax or array syntax: + * - CRUD::column('price')->type('number'); + * - CRUD::addColumn(['name' => 'price', 'type' => 'number']); + */ + } + + /** + * Define what happens when the Create operation is loaded. + * + * @see https://backpackforlaravel.com/docs/crud-operation-create + * @return void + */ + protected function setupCreateOperation() + { + CRUD::setValidation(BrokerAttachmentRequest::class); + + CRUD::addFields([ + [ + 'name' => 'name', + 'type' => 'text' + ], + [ + 'name' => 'size', + 'type' => 'text' + ], + [ + 'name' => 'type', + 'label' => "Type", + 'type' => 'select2_from_array', + 'options' => ['docx' => 'docx', 'xls' => 'xls', 'pdf' => 'pdf'], + 'allows_null' => true, + ], + [ // Upload + 'name' => 'file', + 'label' => 'File', + 'type' => 'upload', + 'upload' => true, + 'disk' => 'uploads', // if you store files in the /public folder, please ommit this; if you store them in /storage or S3, please specify it; + ], + [ + 'name' => 'document_id', + 'type' => 'select', + 'label' => 'Document', + 'entity' => 'document', + 'model' => "App\Models\Document", + 'attribute' => 'name_ru' + ], + [ + 'name' => 'application_id', + 'type' => 'select', + 'label' => 'Application', + 'entity' => 'application', + 'model' => "App\Models\Application", + 'attribute' => 'account_id' + ], + ]); + + /** + * 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(); + } +} diff --git a/app/Http/Controllers/Admin/BrokerDocumentCrudController.php b/app/Http/Controllers/Admin/BrokerDocumentCrudController.php new file mode 100644 index 00000000..dbbe5c2b --- /dev/null +++ b/app/Http/Controllers/Admin/BrokerDocumentCrudController.php @@ -0,0 +1,177 @@ +hasPermissionTo('broker-documents'))){ + $this->crud->denyAccess(['delete', 'update']); + } + CRUD::setModel(\App\Models\BrokerDocument::class); + CRUD::setRoute(config('backpack.base.route_prefix') . '/broker-document'); + CRUD::setEntityNameStrings('broker document', 'broker documents'); + $this->crud->addFilter([ + 'name' => 'business', + 'type' => 'dropdown', + 'label' => trans('app.resource.business') + ], [ + 1 => trans('app.resource.yes'), + 0 => trans('app.resource.no') + ], function ($value) { // if the filter is active + $this->crud->addClause('where', 'business', $value); + }); + + $this->crud->addFilter([ + 'name' => 'company', + 'type' => 'dropdown', + 'label' => trans('app.resource.company') + ], [ + 1 => trans('app.resource.yes'), + 0 => trans('app.resource.no') + ], function ($value) { // if the filter is active + $this->crud->addClause('where', 'company', $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->addColumns([ + [ + 'name' => 'name', + 'type' => 'text', + 'label' => trans('app.resource.name') + ], + [ + 'name' => 'max_size', + 'type' => 'number', + 'label' => trans('app.resource.max_size'), + 'default' => 0 + ], + [ + 'name' => 'order', + 'type' => 'number', + 'label' => trans('app.resource.position'), + 'default' => 0 + ], + [ + 'name' => 'business', + 'type' => 'radio', + 'label' => trans('app.resource.enterpreneurs'), + 'options' => [ + 1 => trans('app.resource.yes'), + 0 => trans('app.resource.no') + ] + ], + [ + 'name' => 'company', + 'type' => 'radio', + 'label' => trans('app.resource.companies'), + 'options' => [ + 1 => trans('app.resource.yes'), + 0 => trans('app.resource.no') + ] + ], + ]); + + /** + * Columns can be defined using the fluent syntax or array syntax: + * - CRUD::column('price')->type('number'); + * - CRUD::addColumn(['name' => 'price', 'type' => 'number']); + */ + } + + /** + * Define what happens when the Create operation is loaded. + * + * @see https://backpackforlaravel.com/docs/crud-operation-create + * @return void + */ + protected function setupCreateOperation() + { + CRUD::setValidation(BrokerDocumentRequest::class); + $this->crud->addFields([ + [ + 'name' => 'name', + 'type' => 'text', + 'label' => 'Name' + ], + [ + 'name' => 'description', + 'type' => 'textarea', + 'label' => 'Description' + ], + [ + 'name' => 'max_size', + 'type' => 'number', + 'label' => 'Max size (KBytes)', + 'default' => 0 + ], + [ + 'name' => 'order', + 'type' => 'number', + 'label' => 'Position', + 'default' => 0 + ], + [ + 'name' => 'business', + 'label' => 'Enterpreneurs', + 'type' => 'checkbox' + ], + [ + 'name' => 'company', + 'label' => 'Companies', + 'type' => 'checkbox' + ], + [ // Checkbox + 'name' => 'is_required', + 'label' => 'Is required?', + 'type' => 'checkbox' + ], + ]); + + + /** + * 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(); + } +} diff --git a/app/Http/Middleware/ClientUserProvider.php b/app/Http/Middleware/ClientUserProvider.php index 8b3cde5d..11a98502 100755 --- a/app/Http/Middleware/ClientUserProvider.php +++ b/app/Http/Middleware/ClientUserProvider.php @@ -4,6 +4,7 @@ use Closure; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; class ClientUserProvider { @@ -14,8 +15,13 @@ class ClientUserProvider * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse */ - public function handle($request, Closure $next){ - config(['auth.guards.api.provider' => 'clients']); + + public function handle($request, Closure $next, $guard = 'api') + { + if (!Auth::guard($guard)->check()) { + return redirect('/'); + } + return $next($request); } } diff --git a/app/Http/Requests/BrokerApplicationRequest.php b/app/Http/Requests/BrokerApplicationRequest.php new file mode 100644 index 00000000..a29d42f2 --- /dev/null +++ b/app/Http/Requests/BrokerApplicationRequest.php @@ -0,0 +1,55 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + // 'name' => 'required|min:5|max:255' + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/app/Http/Requests/BrokerAttachmentRequest.php b/app/Http/Requests/BrokerAttachmentRequest.php new file mode 100644 index 00000000..2c942b70 --- /dev/null +++ b/app/Http/Requests/BrokerAttachmentRequest.php @@ -0,0 +1,55 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + // 'name' => 'required|min:5|max:255' + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/app/Http/Requests/BrokerDocumentRequest.php b/app/Http/Requests/BrokerDocumentRequest.php new file mode 100644 index 00000000..442a2a73 --- /dev/null +++ b/app/Http/Requests/BrokerDocumentRequest.php @@ -0,0 +1,55 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + // 'name' => 'required|min:5|max:255' + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/app/Http/Resources/BrokerApplicationResource.php b/app/Http/Resources/BrokerApplicationResource.php new file mode 100644 index 00000000..8bd64e69 --- /dev/null +++ b/app/Http/Resources/BrokerApplicationResource.php @@ -0,0 +1,31 @@ + $this->id, + 'state' => $this->state, + 'accepted_by' => $this->accepted_by, + 'accepted_date' => $this->accepted_date, + 'approved_by' => $this->approved_by, + 'refine_note' => $this->refine_note, + 'approved_date' => $this->approved_date, + 'questionnaire_path' => $this->questionnaire_path, + 'receipt_path' => $this->receipt_path, + 'broker_attachments' => BrokerAttachmentResource::collection($this->broker_attachments), + 'ticket' => TicketResource::make($this->ticket), + ]; + } +} diff --git a/app/Http/Resources/BrokerAttachmentResource.php b/app/Http/Resources/BrokerAttachmentResource.php new file mode 100644 index 00000000..1c7c99b6 --- /dev/null +++ b/app/Http/Resources/BrokerAttachmentResource.php @@ -0,0 +1,29 @@ + $this->id, + 'attachment_name' => $this->document->name ?: $this->name, + 'attachment_size' => $this->size, + 'attachment_file_type' => $this->type, + 'attachment_file_path' => is_null($this->file) ? null:Storage::url($this->file), + 'document_name' => $this->document->name, + 'document_description' => $this->document->description, + 'document_max_size' => $this->document->max_size, + 'is_required' => $this->document->is_required, + ]; + } +} diff --git a/app/Models/Account.php b/app/Models/Account.php index f19e58d6..f4b767ed 100755 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -86,6 +86,15 @@ public function last_application(){ return $this->applications()->latest()->first(); } + public function broker_applications():HasMany + { + return $this->hasMany(BrokerApplication::class); + } + + public function last_broker_application(){ + return $this->broker_applications()->latest()->first(); + } + /* |-------------------------------------------------------------------------- | SCOPES @@ -117,11 +126,6 @@ public function getCanExtendAttribute() if($application = $this->last_application()){ return $application->state == 'approved' && $this->expires_at->lte(Carbon::now()->subMonths($month)); } -// if($this->expires_at->gte(Carbon::now()->subMonths($month))){ -// Log::info($this->expires_at); -// }else{ -// Log::info(Carbon::now()->subMonths($month)); -// } return !empty($this->legalization_number) && !empty( $this->expires_at) && $this->expires_at->gte(Carbon::now()->subMonths($month)); } @@ -136,6 +140,28 @@ public function getCountryNameAttribute(){ return $this->country->name; } + + public function getCanApplyBrokerAttribute(){ + return is_null($this->last_application()); + } + + public function getCanExtendBrokerAttribute() + { + $month = Config::get('settings.legalization_extend') ?? 1; + + if($application = $this->last_application()){ + return $application->state == 'approved' && $this->expires_at->lte(Carbon::now()->subMonths($month)); + } + + return !empty($this->legalization_number) && !empty( $this->expires_at) && $this->expires_at->gte(Carbon::now()->subMonths($month)); + } + + public function getApplicationBrokerStatusAttribute(){ + $application = $this->last_application(); + + return $application->state ?? null; + } + /* |-------------------------------------------------------------------------- | MUTATORS diff --git a/app/Models/BrokerApplication.php b/app/Models/BrokerApplication.php new file mode 100644 index 00000000..f3f53dcb --- /dev/null +++ b/app/Models/BrokerApplication.php @@ -0,0 +1,80 @@ +id) .'" data-toggle="tooltip"> + + + + + ' . trans('app.last_updates.preview') . ''; + } + + /* + |-------------------------------------------------------------------------- + | RELATIONS + |-------------------------------------------------------------------------- + */ + public function account(){ + return $this->belongsTo(Account::class, 'account_id'); + } + + public function broker_attachments(){ + return $this->hasMany(BrokerAttachment::class) + ->leftJoin('broker_documents','broker_attachments.broker_document_id','=','broker_documents.id') + ->select('broker_attachments.*','order') + ->orderBy('broker_documents.order'); + } + + public function ticket():HasOne{ + return $this->hasOne(Ticket::class); + } + + /* + |-------------------------------------------------------------------------- + | SCOPES + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | ACCESSORS + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | MUTATORS + |-------------------------------------------------------------------------- + */ +} diff --git a/app/Models/BrokerAttachment.php b/app/Models/BrokerAttachment.php new file mode 100644 index 00000000..50bb8dbe --- /dev/null +++ b/app/Models/BrokerAttachment.php @@ -0,0 +1,82 @@ +belongsTo(BrokerApplication::class, 'broker_application_id'); + } + + public function document(){ + return $this->belongsTo(BrokerDocument::class, 'broker_document_id'); + } + + /* + |-------------------------------------------------------------------------- + | SCOPES + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | ACCESSORS + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | MUTATORS + |-------------------------------------------------------------------------- + */ + public function setFileAttribute($value) + { + $attribute_name = 'file'; + $disk = 'public'; + $destination_path = 'uploads/broker_attachments'; + + $this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path); + + // return $this->attributes[{$attribute_name}]; // uncomment if this is a translatable field + } + + public static function boot() + { + parent::boot(); + static::deleting(function($obj) { + \Storage::disk('public')->delete($obj->file); + }); + } +} diff --git a/app/Models/BrokerDocument.php b/app/Models/BrokerDocument.php new file mode 100644 index 00000000..9d581a53 --- /dev/null +++ b/app/Models/BrokerDocument.php @@ -0,0 +1,72 @@ +belongsToMany(BrokerAttachment::class); + } + + /* + |-------------------------------------------------------------------------- + | SCOPES + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | ACCESSORS + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | MUTATORS + |-------------------------------------------------------------------------- + */ +} diff --git a/config/auth.php b/config/auth.php index 84eab93a..d596e849 100755 --- a/config/auth.php +++ b/config/auth.php @@ -72,6 +72,7 @@ 'clients' => [ 'driver' => 'eloquent', 'model' => App\Models\Client::class, + 'table'=>'clients' ], // 'users' => [ diff --git a/database/migrations/2023_03_10_143604_create_broker_documents_table.php b/database/migrations/2023_03_10_143604_create_broker_documents_table.php new file mode 100644 index 00000000..1254aa90 --- /dev/null +++ b/database/migrations/2023_03_10_143604_create_broker_documents_table.php @@ -0,0 +1,37 @@ +id(); + $table->text('name')->nullable(); + $table->text('description')->nullable(); + $table->double('max_size')->nullable(); + $table->boolean('business')->default(0); + $table->boolean('company')->default(0); + $table->integer('order')->default(0); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('broker_documents'); + } +}; diff --git a/database/migrations/2023_03_10_143911_create_broker_applications_table.php b/database/migrations/2023_03_10_143911_create_broker_applications_table.php new file mode 100644 index 00000000..cfb351f5 --- /dev/null +++ b/database/migrations/2023_03_10_143911_create_broker_applications_table.php @@ -0,0 +1,40 @@ +id(); + $table->boolean('status')->default(0); + $table->foreignId('account_id')->references('id')->on('accounts')->onDelete('cascade'); + $table->string('state')->default('new'); + $table->string('accepted_by')->nullable(); + $table->string('modified_by')->nullable(); + $table->string('approved_by')->nullable(); + $table->string('accepted_date')->nullable(); + $table->string('approved_date')->nullable(); + $table->text('refine_note')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('broker_applications'); + } +}; diff --git a/database/migrations/2023_03_10_143943_create_broker_attachments_table.php b/database/migrations/2023_03_10_143943_create_broker_attachments_table.php new file mode 100644 index 00000000..e905e562 --- /dev/null +++ b/database/migrations/2023_03_10_143943_create_broker_attachments_table.php @@ -0,0 +1,37 @@ +id(); + $table->string('name')->nullable(); + $table->string('size')->nullable(); + $table->string('type')->nullable(); + $table->string('file')->nullable(); + $table->foreignId('broker_document_id')->onDelete('cascade'); + $table->foreignId('broker_application_id')->references('id')->on('applications')->onDelete('cascade'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('broker_attachments'); + } +}; diff --git a/database/migrations/2023_03_10_145400_add_broker_application_to_tickets_table.php b/database/migrations/2023_03_10_145400_add_broker_application_to_tickets_table.php new file mode 100644 index 00000000..d9983e9a --- /dev/null +++ b/database/migrations/2023_03_10_145400_add_broker_application_to_tickets_table.php @@ -0,0 +1,32 @@ +foreignId('broker_application_id')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('tickets', function (Blueprint $table) { + // + }); + } +}; diff --git a/database/migrations/2023_03_15_134347_add_required_to_broker_documents_table.php b/database/migrations/2023_03_15_134347_add_required_to_broker_documents_table.php new file mode 100644 index 00000000..f95cea1f --- /dev/null +++ b/database/migrations/2023_03_15_134347_add_required_to_broker_documents_table.php @@ -0,0 +1,32 @@ +boolean('is_required')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('broker_documents', function (Blueprint $table) { + // + }); + } +}; diff --git a/resources/views/admin/broker_application_preview.blade.php b/resources/views/admin/broker_application_preview.blade.php new file mode 100644 index 00000000..dbce9f9d --- /dev/null +++ b/resources/views/admin/broker_application_preview.blade.php @@ -0,0 +1,313 @@ +@extends(backpack_view('blank')) + +@section('content') + + + + +
+
+ @if ($application->state == 'new') +
+ @csrf + +
+ @elseif ($application->state == 'accepted') + + + + + @endif + @if($application->ticket) + {{ trans('app.last_updates.go_to_ticket') }} + @else + + + @endif +
+
+
+
+
+
+
{{ trans('app.last_updates.application') }}
+
+ +
{{ trans('app.application.'.$application->state) }}
+
+
+ +
{{ $application->accepted_by }}
+
+
+ +
{{ $application->accepted_date }}
+
+
+ +
{{ $application->approved_by }}
+
+
+ +
{{ $application->approved_date }}
+
+
+ +
{{ $application->modified_by }}
+
+
+ +
{{ $application->updated_at }}
+
+ +
+
+
+ +
+ +
+
+
+
+ @include('admin.account.'.$application->account->type,['account'=>$application->account]) +
+
+
+
+ + + + + + + + + + @foreach ($application->broker_attachments as $attachment) + + + @if ($attachment->file) + + + + @else + + @endif + + + @endforeach + +
@lang('app.application.name')@lang('app.application.size')@lang('app.application.type')
+ + {{ $attachment->name }} + + + {{ $attachment->size }} Kb + + {{ $application->type }} + {{ $attachment->name }}
+
+
+
+
+ + + +@endsection diff --git a/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php b/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php index 712d86c7..8df9bc99 100755 --- a/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php +++ b/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php @@ -64,3 +64,7 @@ @endif + + + + \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index 86e8bcdd..d91fd4dd 100755 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,7 @@ group(function () { + + Route::middleware(['auth.client', 'auth:api', 'auth:sanctum'])->group(function () { /** * Client endpoints */ @@ -80,6 +81,17 @@ }); + /** + * Broker-Application endpoints + */ + Route::group(['prefix' => 'broker-application'], function () { + Route::get('/',[BrokerApplicationController::class,'get']); + Route::get('/oprosnik',[BrokerApplicationController::class,'downloadQuestionaire']); + Route::get('new',[BrokerApplicationController::class,'create']); + Route::post('upload/{attachment_id}',[BrokerApplicationController::class,'upload']); + Route::post('apply',[BrokerApplicationController::class,'apply']); + }); + }); }); diff --git a/routes/backpack/custom.php b/routes/backpack/custom.php index 31c94b87..e8960679 100755 --- a/routes/backpack/custom.php +++ b/routes/backpack/custom.php @@ -43,6 +43,7 @@ Route::get('/chat', [TicketController::class, 'chat'])->name('chat'); Route::get('/preview/{id}', [ResourceController::class, 'previewAccountAdmin']); Route::get('/preview-application/{id}',[ResourceController::class, 'previewApplicationAdmin']); + Route::get('/preview-broker-application/{id}',[ResourceController::class, 'previewBrokerApplicationAdmin']); Route::get('/export-account-admin/{id}', [ExportController::class, 'export']); Route::post('/create-application-ticket', [TicketController::class, 'createAppTicket']); Route::get('/create-account-client/{id}', [ResourceController::class, 'createAccountClient']); @@ -55,4 +56,7 @@ Route::crud('department', 'DepartmentCrudController'); Route::crud('resolution', 'ResolutionCrudController'); Route::crud('resolutionbasis', 'ResolutionbasisCrudController'); + Route::crud('broker-document', 'BrokerDocumentCrudController'); + Route::crud('broker-application', 'BrokerApplicationCrudController'); + Route::crud('broker-attachment', 'BrokerAttachmentCrudController'); }); // this should be the absolute last line of this file diff --git a/storage/api-docs/api-docs.json b/storage/api-docs/api-docs.json index 47122b90..7fcaa573 100755 --- a/storage/api-docs/api-docs.json +++ b/storage/api-docs/api-docs.json @@ -1817,6 +1817,250 @@ ] } }, + "/api/broker-application": { + "get": { + "tags": ["Broker-Application"], + "summary": "Get accounts Legalization application", + "parameters": [{ + "name": "X-Localization", + "in": "header", + "description": "Localization", + "required": false, + "schema": { + "type": "string" + }, + "examples": { + "ru": { + "summary": "Russian localization", + "value": "ru" + }, + "en": { + "summary": "English localization", + "value": "en" + }, + "tm": { + "summary": "Turkmen localization", + "value": "tm" + } + } + }], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + }, + "401": { + "description": "Unauthorized" + } + }, + "security":[ + { + "bearerAuth": [] + } + ] + } + }, + "/api/broker-application/new": { + "get": { + "tags": ["Broker-Application"], + "summary": "Create,make new Legalization application", + "parameters": [{ + "name": "X-Localization", + "in": "header", + "description": "Localization", + "required": false, + "schema": { + "type": "string" + }, + "examples": { + "ru": { + "summary": "Russian localization", + "value": "ru" + }, + "en": { + "summary": "English localization", + "value": "en" + }, + "tm": { + "summary": "Turkmen localization", + "value": "tm" + } + } + }], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + }, + "401": { + "description": "Unauthorized" + } + }, + "security":[ + { + "bearerAuth": [] + } + ] + } + }, + "/api/broker-application/upload/{attachment_id}": { + "post": { + "tags": ["Broker-Application"], + "summary": "Upload document to application", + "parameters": [{ + "name": "attachment_id", + "in": "path", + "description": "Attachment id", + "required": true, + "schema": { + "type": "integer" + } + }], + "requestBody": { + "content": { + "multipart/form-data:": { + "schema": { + "properties": { + "file": { + "type": "string", + "format": "binary", + "required": true + } + }, + "type": "object" + } + } + } + }, + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + }, + "401": { + "description": "Unauthorized" + } + }, + "security":[ + { + "bearerAuth": [] + } + ] + } + }, + "/api/broker-application/apply": { + "post": { + "tags": ["Broker-Application"], + "summary": "Commit,apply application. send to review ", + "parameters": [{ + "name": "X-Localization", + "in": "header", + "description": "Localization", + "required": false, + "schema": { + "type": "string" + }, + "examples": { + "ru": { + "summary": "Russian localization", + "value": "ru" + }, + "en": { + "summary": "English localization", + "value": "en" + }, + "tm": { + "summary": "Turkmen localization", + "value": "tm" + } + } + }], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "example": { + "data": { + "attachment_id": 1, + "attachment_name": "Pasport Kopia", + "attachment_size": "10", + "attachment_file_type": "pdf", + "attachment_file_path": "/storage/mtorage/gdeto/tam", + "document_name": "Pasport Kopia", + "document_description": "Pasport kopialay", + "document_max_size": "10" + } + } + } + } + } + }, + "401": { + "description": "Unauthorized" + } + }, + "security":[ + { + "bearerAuth": [] + } + ] + } + }, + "/api/broker-application/oprosnik": { + "get": { + "tags": ["Broker-Application"], + "summary": "Download oprosnik", + "parameters": [{ + "name": "X-Localization", + "in": "header", + "description": "Localization", + "required": false, + "schema": { + "type": "string" + }, + "examples": { + "ru": { + "summary": "Russian localization", + "value": "ru" + }, + "en": { + "summary": "English localization", + "value": "en" + }, + "tm": { + "summary": "Turkmen localization", + "value": "tm" + } + } + }], + "security":[ + { + "bearerAuth": [] + } + ] + } + }, "/api/contract": { "post": { "tags": ["Contract"],