From b3e7d17d31f399296fd7075f171ca9a61d9eb53a Mon Sep 17 00:00:00 2001 From: Thekindbull Date: Mon, 15 Sep 2025 23:37:40 +0800 Subject: [PATCH] client form updated & modules removed --- .../Controllers/ClientsTableController.php | 4 +- app/Livewire/ClientsTable.php | 4 +- app/Livewire/ContractsTable.php | 44 +-- app/Models/Agent/AgentStatus.php | 7 - app/Models/Deal/Deal.php | 7 +- .../Controllers/AdminBitrixController.php | 2 +- .../ClientCreateForm/Config/config.php | 5 + ...23040_create_client_create_forms_table.php | 27 ++ .../ClientCreateForm/Helpers/helper.php | 65 +++++ .../ClientCreateFormController.php | 17 ++ .../Http/Livewire/ClientCreateForm.php | 31 +++ .../Http/Livewire/ClientCreateLivewire.php | 181 +++++++++++++ .../Http/Livewire/FormStatus.php | 11 + .../Models/ClientCreateForm.php | 11 + .../Providers/ModuleServiceProvider.php | 81 ++++++ .../Providers/RouteServiceProvider.php | 24 ++ app/Modules/ClientCreateForm/Routes/web.php | 13 + .../ClientCreateForm/Views/index.blade.php | 4 + .../Views/livewire/form.blade.php | 253 ++++++++++++++++++ app/Modules/Contracts/Helpers/helper.php | 17 ++ .../Http/Controllers/ContractsController.php | 7 + .../Http/Livewire/ContractsTableLivewire.php | 10 +- app/Modules/Contracts/Routes/web.php | 2 + .../Views/livewire/table/index.blade.php | 13 +- app/Modules/Main/Config/config.php | 5 + .../2025_09_15_032348_create_mains_table.php | 27 ++ .../Main/Http/Controllers/MainController.php | 17 ++ app/{ => Modules/Main}/Models/Agent/Agent.php | 4 +- app/Modules/Main/Models/Agent/AgentStatus.php | 7 + app/{ => Modules/Main}/Models/City.php | 2 +- .../Main}/Models/Company/Company.php | 2 +- .../Main}/Models/Company/CompanyAdmin.php | 21 +- .../Main}/Models/Company/CompanyStatus.php | 2 +- .../Main}/Models/Company/CompanyType.php | 8 +- .../Main}/Models/Company/Details.php | 4 +- app/{ => Modules/Main}/Models/Complex.php | 5 +- app/Modules/Main/Models/Main.php | 11 + .../Main/Providers/ModuleServiceProvider.php | 68 +++++ .../Main/Providers/RouteServiceProvider.php | 24 ++ app/Modules/Main/Routes/web.php | 13 + app/Modules/Main/Views/index.blade.php | 4 + app/Modules/Payment/Models/Payment.php | 6 +- app/Modules/Payment/Traits/Paymentable.php | 2 +- app/Providers/AppServiceProvider.php | 15 +- .../views/clients/contract/index.blade.php | 104 ++++--- resources/views/clients/table.blade.php | 6 +- .../views/livewire/clients-table.blade.php | 101 ++++--- resources/views/user/dashboard.blade.php | 11 +- 48 files changed, 1153 insertions(+), 156 deletions(-) delete mode 100644 app/Models/Agent/AgentStatus.php create mode 100644 app/Modules/ClientCreateForm/Config/config.php create mode 100644 app/Modules/ClientCreateForm/Database/Migrations/2025_09_15_023040_create_client_create_forms_table.php create mode 100644 app/Modules/ClientCreateForm/Helpers/helper.php create mode 100644 app/Modules/ClientCreateForm/Http/Controllers/ClientCreateFormController.php create mode 100644 app/Modules/ClientCreateForm/Http/Livewire/ClientCreateForm.php create mode 100644 app/Modules/ClientCreateForm/Http/Livewire/ClientCreateLivewire.php create mode 100644 app/Modules/ClientCreateForm/Http/Livewire/FormStatus.php create mode 100644 app/Modules/ClientCreateForm/Models/ClientCreateForm.php create mode 100644 app/Modules/ClientCreateForm/Providers/ModuleServiceProvider.php create mode 100644 app/Modules/ClientCreateForm/Providers/RouteServiceProvider.php create mode 100644 app/Modules/ClientCreateForm/Routes/web.php create mode 100644 app/Modules/ClientCreateForm/Views/index.blade.php create mode 100644 app/Modules/ClientCreateForm/Views/livewire/form.blade.php create mode 100644 app/Modules/Main/Config/config.php create mode 100644 app/Modules/Main/Database/Migrations/2025_09_15_032348_create_mains_table.php create mode 100644 app/Modules/Main/Http/Controllers/MainController.php rename app/{ => Modules/Main}/Models/Agent/Agent.php (96%) create mode 100644 app/Modules/Main/Models/Agent/AgentStatus.php rename app/{ => Modules/Main}/Models/City.php (89%) rename app/{ => Modules/Main}/Models/Company/Company.php (94%) rename app/{ => Modules/Main}/Models/Company/CompanyAdmin.php (81%) rename app/{ => Modules/Main}/Models/Company/CompanyStatus.php (79%) rename app/{ => Modules/Main}/Models/Company/CompanyType.php (57%) rename app/{ => Modules/Main}/Models/Company/Details.php (96%) rename app/{ => Modules/Main}/Models/Complex.php (71%) create mode 100644 app/Modules/Main/Models/Main.php create mode 100644 app/Modules/Main/Providers/ModuleServiceProvider.php create mode 100644 app/Modules/Main/Providers/RouteServiceProvider.php create mode 100644 app/Modules/Main/Routes/web.php create mode 100644 app/Modules/Main/Views/index.blade.php diff --git a/app/Http/Controllers/ClientsTableController.php b/app/Http/Controllers/ClientsTableController.php index ea299fb..ff9aad1 100644 --- a/app/Http/Controllers/ClientsTableController.php +++ b/app/Http/Controllers/ClientsTableController.php @@ -5,8 +5,8 @@ use Illuminate\Http\Request; use App\Models\Deal\Deal; -use App\Models\Company\CompanyAdmin; -use App\Models\City; +use Modules\Main\Models\Company\CompanyAdmin; +use Modules\Main\Models\City; class ClientsTableController extends Controller { diff --git a/app/Livewire/ClientsTable.php b/app/Livewire/ClientsTable.php index 3a02df4..df93ce3 100644 --- a/app/Livewire/ClientsTable.php +++ b/app/Livewire/ClientsTable.php @@ -7,8 +7,8 @@ use Livewire\WithoutUrlPagination; use App\Models\User; -use App\Models\Agent\Agent; -use App\Models\Company\CompanyAdmin; +use Modules\Main\Models\Agent\Agent; +use Modules\Main\Models\Company\CompanyAdmin; use App\Models\Deal\Deal; use App\Models\Deal\DealStatus; use App\Models\Deal\Client; diff --git a/app/Livewire/ContractsTable.php b/app/Livewire/ContractsTable.php index c309e35..af23c8e 100644 --- a/app/Livewire/ContractsTable.php +++ b/app/Livewire/ContractsTable.php @@ -6,14 +6,14 @@ use Livewire\WithPagination; use Livewire\WithoutUrlPagination; -use App\Models\Agent\Agent; -use App\Models\Company\CompanyAdmin; +use Modules\Main\Models\Agent\Agent; +use Modules\Main\Models\Company\CompanyAdmin; use App\Models\Deal\Deal; use App\Models\Deal\DealStatus; class ContractsTable extends Component - { +{ use WithPagination, WithoutUrlPagination; public $status; @@ -21,58 +21,58 @@ class ContractsTable extends Component public $mode;//short || full public function mount($status = null, $count = 10, $mode = 'full') - { + { $this->status = $status; $this->count = $count; $this->mode = $mode; - } + } public function getContracts() - { + { $deals = false; $user = auth()->user(); if ($agent = Agent::where('user_id', $user->id)->first()) - { + { $deals = Deal::where('agent_id', $agent->id); - } + } elseif ($admin = CompanyAdmin::where('user_id', $user->id)->first()) - { + { $deals = Deal::whereIn('agent_id', function ($query) use ($admin) - { + { $query->select('id'); $query->from('agents'); $query->where('company_id', $admin->company_id); - }); - } - return $deals; + }); } + return $deals; + } public function render() - { + { $deals = $this->getDeals(); if ($this->status && $this->status == DealStatus::UNIQUE) - { + { $deals = $deals ->whereIn('status', [DealStatus::UNIQUE]) ->orderBy('id', 'desc')->paginate($this->count, ['*'], 'unique_clients'); - } + } elseif ($this->status && $this->status == DealStatus::NOT_UNIQUE) - { + { $deals = $deals ->whereIn('status', [DealStatus::MODERATION, DealStatus::NEW , DealStatus::NOT_UNIQUE]) ->orderBy('id', 'desc')->paginate($this->count, ['*'], 'not_unique_clients'); - } + } else - { + { $deals = $deals->orderBy('id', 'desc')->paginate($this->count, ['*'], 'all_clients'); - } + } ; return view( 'livewire.clients-table', [ - 'deals' => $deals, + 'deals' => $deals, 'statuses' => DealStatus::class ] ); - } } +} diff --git a/app/Models/Agent/AgentStatus.php b/app/Models/Agent/AgentStatus.php deleted file mode 100644 index 7284c77..0000000 --- a/app/Models/Agent/AgentStatus.php +++ /dev/null @@ -1,7 +0,0 @@ -belongsTo(\App\Models\Complex::class); + return $this->belongsTo(Complex::class); } public function user() { @@ -32,7 +35,7 @@ public function user() } public function agent() { - return $this->belongsTo(\App\Models\Agent\Agent::class, 'agent_id'); + return $this->belongsTo(Agent::class, 'agent_id'); } public function contract() diff --git a/app/Modules/Admin/Http/Controllers/AdminBitrixController.php b/app/Modules/Admin/Http/Controllers/AdminBitrixController.php index 8ae07b0..d4860d2 100644 --- a/app/Modules/Admin/Http/Controllers/AdminBitrixController.php +++ b/app/Modules/Admin/Http/Controllers/AdminBitrixController.php @@ -7,7 +7,7 @@ use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; -use App\Models\Agent\Agent; +use Modules\Main\Models\Agent\Agent; use App\Models\Deal\Contract; use App\Models\Deal\Deal; use App\Models\Deal\DealStatus; diff --git a/app/Modules/ClientCreateForm/Config/config.php b/app/Modules/ClientCreateForm/Config/config.php new file mode 100644 index 0000000..ce09543 --- /dev/null +++ b/app/Modules/ClientCreateForm/Config/config.php @@ -0,0 +1,5 @@ +id(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('client_create_forms'); + } +}; diff --git a/app/Modules/ClientCreateForm/Helpers/helper.php b/app/Modules/ClientCreateForm/Helpers/helper.php new file mode 100644 index 0000000..dfb6dc8 --- /dev/null +++ b/app/Modules/ClientCreateForm/Helpers/helper.php @@ -0,0 +1,65 @@ +user()->id)->first()) + { + return $adminAccount->company; + } + else + { + return false; + } + } +} + +if (!function_exists('GetAvailableAgents')) +{ + function GetAvailableAgents() + { + $agents = []; + if ($adminCompany = AdminCompanyOfUser()) + { + $agents = Agent::where('company_id', $adminCompany->id); + } + else + { + $agents = Agent::where('user_id', auth()->user()->id); + } + + $agents->with('company:id,name'); + $agents->with('user:id,name'); + return $agents->get()->toArray(); + } +} + +if (!function_exists('GetAvailableComplexes')) +{ + function GetAvailableComplexes() + { + $complexes = false; + if ($adminCompany = AdminCompanyOfUser()) + { + $complexes = Complex::where('city_id', $adminCompany->city_id); + } + else + { + if ($agent = Agent::where('user_id', auth()->user()->id)->first()) + { + $complexes = Complex::where('city_id', $agent->company->city_id); + } + } + if ($complexes) + { + return $complexes->get()->toArray(); + } + return []; + } +} \ No newline at end of file diff --git a/app/Modules/ClientCreateForm/Http/Controllers/ClientCreateFormController.php b/app/Modules/ClientCreateForm/Http/Controllers/ClientCreateFormController.php new file mode 100644 index 0000000..80fdb9c --- /dev/null +++ b/app/Modules/ClientCreateForm/Http/Controllers/ClientCreateFormController.php @@ -0,0 +1,17 @@ + 'Необходимо указать имя клиента', + 'clients.*.secondName.required' => 'Необходимо указать фамилию клиента', + 'clients.*.phones.*.required' => 'Необходимо указать телефон', + 'clients.*.phones.*.regex' => 'Телефон должен быть в международном формате', + 'clients.*.phones.*.unique' => 'Клиент с таким телефоном уже существует', + 'agent.integer' => 'Необходимо указать агента, от которого добавляется контакт' + ]; + protected function rules() + { + return [ + //'agent' => ['required', 'integer'], + //'currentClient' => ['required', 'string', 'max:255'], + 'currentClient.firstName' => ['required', 'string', 'max:255'], + 'currentClient.secondName' => ['required', 'string', 'max:255'], + 'currentClient.phones.*' => ['required', 'string', 'regex:/^(\+7)([0-9]{3})([-]{1})([0-9]{3})([-]{1})([0-9]{4})/i'] + //'client.phone' => ['required', 'string', 'regex:/^\+7 \d{3} \d{3}-\d{2}-\d{2}$/'], + //'client.phone' => ['required', 'string'] + ]; + } +} \ No newline at end of file diff --git a/app/Modules/ClientCreateForm/Http/Livewire/ClientCreateLivewire.php b/app/Modules/ClientCreateForm/Http/Livewire/ClientCreateLivewire.php new file mode 100644 index 0000000..79ca4ec --- /dev/null +++ b/app/Modules/ClientCreateForm/Http/Livewire/ClientCreateLivewire.php @@ -0,0 +1,181 @@ +complexes = GetAvailableComplexes(); + $this->availableAgents = GetAvailableAgents(); + $this->maxClientsCount = 2; + $this->clientLabels = ['Основной контакт', 'Супруг/супруга']; + + $this->status = FormStatus::NEW; + $this->secondaryClient = false; + $this->addSecondaryClient = true; + if (count($this->availableAgents) == 1) //чтобы не выводить в форму + { //и не заставлять пользователя указывать вручную + $this->agent = $this->availableAgents[0]['id']; + } + $this->addClient(); + $this->addClient();//по-умолчанию сразу выводить супруга + $this->setCurrentClient(0); + } + public function updated($propertyName) + { + $this->status = FormStatus::NEW; + } + public function addClient() + { + if (!isset($this->clients)) + { + $this->clients = []; + } + if ($this->maxClientsCount > count($this->clients)) + { + $this->clients[] = [ + 'firstName' => '', + 'secondName' => '', + 'phones' => [''], + 'complexId' => '' + ]; + } + $this->setCurrentClient(count($this->clients) - 1); + } + public function deleteCurrentContact() + { + if ($this->currentClientIndex > 0) + { + unset($this->clients[$this->currentClientIndex]); + $this->clients = array_values($this->clients); + $this->updateCurrentClientIndex($this->currentClientIndex - 1); + } + } + public function setCurrentClient($index) + { + $this->saveClient(); + $this->updateCurrentClientIndex($index); + } + private function updateCurrentClientIndex($index) + { + $this->currentClient = $this->clients[$index]; + $this->currentClientIndex = $index; + } + public function saveClient() + { + if (isset($this->currentClientIndex)) + { + //$this->form->validate(); + $this->clients[$this->currentClientIndex] = $this->currentClient; + } + } + public function addPhoneForClient() + { + $this->currentClient['phones'][] = ''; + + } + public function render() + { + return view( + 'clientcreateform::livewire.form' + ); + } + public function rendered() + { + $this->dispatch('phoneInputAdded'); + } + public function resetData() + { + $this->mount(); + } + public function back() + { + $this->status = FormStatus::NEW; + } + + //далее - сохранение клиента в базу и отправка в битрикс. + //надо разделить на invoke классы! + /*public function save() + { + $validated = $this->form->validate(); + $newUser = User::updateOrCreate( + ['phone' => $this->client['phone']], + [ + 'name' => trim($this->client['firstName'] . ' ' . $this->client['secondName']), + 'phone' => $this->client['phone'] + ] + ); + $data = [ + 'agent_id' => $this->agent + , + 'client_id' => $newUser->id + , + 'complex_id' => $this->client['complexId'] + ]; + + if ($newDeal = Deal::create($data)) + { + if ($bitrixId = $this->sendToBitrix($newDeal)) + { + $newDeal->bitrix_id = $bitrixId; + $newDeal->status = DealStatus::MODERATION; + $newDeal->save(); + $this->bitrixId = $bitrixId; + return $this->status = FormStatus::SUCCESS; + } + else + { + $newDeal->delete(); + } + } + return $this->status = FormStatus::ERROR; + } + public function sendToBitrix(Deal $deal) + { + $agent = $deal->agent; + $agentName = $agent->user->getPartialsName(); + $data = [ + 'CLIENT_FIRST_NAME' => $this->client['firstName'], + 'CLIENT_SECOND_NAME' => $this->client['secondName'], + 'CLIENT_PHONE' => '+7' . $this->client['phone'], + 'BROKER_FIRST_NAME' => $agentName['firstName'], + 'BROKER_SECOND_NAME' => $agentName['secondName'], + 'BROKER_PHONE' => $agent->user->phone, + 'BROKER_INN' => $agent->company->inn, + //'BROKER_CONTACT' => $agent->bitrixId(), + 'OBJECT_NAME' => Complex::find($this->client['complexId'])->name, + 'CALLBACK_URL' => route('api.client', ['hash' => $deal->confirmToken]), + ]; + $sender = new SendClient($deal->id, $data); + if ($bitrixId = $agent->bitrixId()) + { + $sender->setAgentId($bitrixId); + } + $response = $sender->send(); + if ($response) + { + return $response; + } + else + { + return false; + } + }*/ +} \ No newline at end of file diff --git a/app/Modules/ClientCreateForm/Http/Livewire/FormStatus.php b/app/Modules/ClientCreateForm/Http/Livewire/FormStatus.php new file mode 100644 index 0000000..59949f1 --- /dev/null +++ b/app/Modules/ClientCreateForm/Http/Livewire/FormStatus.php @@ -0,0 +1,11 @@ +app->register(RouteServiceProvider::class); + } + + public function boot() + { + $this->registerViews(); + $this->registerLivewireViews(); + $this->registerMigrations(); + $this->registerConfig(); + $this->registerComponent(); + $this->registerLivewire(); + $this->registerHelpers(); + } + + protected function registerViews() + { + $moduleViewsPath = __DIR__ . '/../Views'; + $this->loadViewsFrom( + $moduleViewsPath, + strtolower($this->moduleName) + ); + } + + protected function registerLivewireViews() + { + $moduleViewsPath = __DIR__ . '/../Views/livewire'; + $this->loadViewsFrom( + $moduleViewsPath, + strtolower($this->moduleName) + ); + } + + protected function registerMigrations() + { + $this->loadMigrationsFrom( + app_path('Modules/' . $this->moduleName . '/Database/Migrations') + ); + } + + protected function registerConfig() + { + $path = app_path('Modules/' . $this->moduleName . '/Config/config.php'); + $this->mergeConfigFrom( + $path, + strtolower($this->moduleName) + ); + } + + protected function registerLivewire() + { + Livewire::component('ClientCreator', \Modules\ClientCreateForm\Http\Livewire\ClientCreateLivewire::class); + } + + protected function registerComponent() + { + //Blade::component('', \Modules\\Http\Components\::class); + } + + protected function registerHelpers() + { + $files = glob(__DIR__ . '/../Helpers/' . "*.php"); + foreach ($files as $key => $file) + { + require_once $file; + } + } +} \ No newline at end of file diff --git a/app/Modules/ClientCreateForm/Providers/RouteServiceProvider.php b/app/Modules/ClientCreateForm/Providers/RouteServiceProvider.php new file mode 100644 index 0000000..8eed911 --- /dev/null +++ b/app/Modules/ClientCreateForm/Providers/RouteServiceProvider.php @@ -0,0 +1,24 @@ +registerWebRoutes(); + } + + protected function registerWebRoutes() + { + //Add Web Routes with web Guard + Route::middleware('web') + //Set Default Controllers Namespace + ->namespace('Modules\\ClientCreateForm\\Http\\Controllers') + ->group(app_path('Modules/ClientCreateForm/Routes/web.php')); + } +} \ No newline at end of file diff --git a/app/Modules/ClientCreateForm/Routes/web.php b/app/Modules/ClientCreateForm/Routes/web.php new file mode 100644 index 0000000..83a5bab --- /dev/null +++ b/app/Modules/ClientCreateForm/Routes/web.php @@ -0,0 +1,13 @@ +group(function() { + + Route::get('/clientCreateForm', [ClientCreateFormController::class, 'index']); + + Route::middleware(['hasAccess'])->group(function() { + /** Routes that need to be protected - Маршруты которые нужно защитить */ + }); +}); \ No newline at end of file diff --git a/app/Modules/ClientCreateForm/Views/index.blade.php b/app/Modules/ClientCreateForm/Views/index.blade.php new file mode 100644 index 0000000..f8198cf --- /dev/null +++ b/app/Modules/ClientCreateForm/Views/index.blade.php @@ -0,0 +1,4 @@ +@extends('layouts.app') + @section('content') +

Example views

+ @endsection \ No newline at end of file diff --git a/app/Modules/ClientCreateForm/Views/livewire/form.blade.php b/app/Modules/ClientCreateForm/Views/livewire/form.blade.php new file mode 100644 index 0000000..9150d01 --- /dev/null +++ b/app/Modules/ClientCreateForm/Views/livewire/form.blade.php @@ -0,0 +1,253 @@ + +
+
+
+ Загрузка формы... +
+
+
+ @if ($status == FormStatus::NEW || $status == FormStatus::READY) +
+ Добавить клиента +
+ +
+
+
+
+
+ + + @error('currentClient.firstName') + + {{ $message }} + + @enderror +
+
+
+
+ + + @error('currentClient.secondName') + + {{ $message }} + + @enderror +
+ +
+
+ @foreach ($currentClient['phones'] as $phoneKey => $phone) +
+
+
+ + + @error('currentClient.phone.{{ $phoneKey }}') + + {{ $message }} + + @enderror +
+ @if (count($currentClient['phones']) == $phoneKey + 1) + + + + + + + @endif +
+
+ @endforeach + +
+ @if ($currentClientIndex > 0) + + @endif +
+
+ + + @error('client.complexId') + + {{ $message }} + + @enderror +
+ + @if (count($availableAgents) > 1) +
+ + + @error('agent') + + {{ $message }} + + @enderror +
+ @endif + + @if ($status == FormStatus::READY && !$errors->any()) +
+ +
+ @else +
+ +
+ @endif + @endif + + @if ($status == FormStatus::SUCCESS) +
+ + + + +
+ +
Клиент добавлен
+
Мы проверим его уникальность и направим Вам информацию в личном + кабинете
+
+ +
+ @endif + + @if ($status == FormStatus::ERROR) +
+ + + + +
+ +
Ой!
+
Кажется, возникла проблема на нашей стороне, мы уже ее решаем. + Попробуйте зайти сюда позже.
+
+ +
+ @endif +
+ @script + + @endscript +
diff --git a/app/Modules/Contracts/Helpers/helper.php b/app/Modules/Contracts/Helpers/helper.php index 0d12600..a45766d 100644 --- a/app/Modules/Contracts/Helpers/helper.php +++ b/app/Modules/Contracts/Helpers/helper.php @@ -1,5 +1,6 @@ ContractStatus::getName(ContractStatus::TREATY), ]; } +} + +if (!function_exists('GetAgentPaymentForContract')) +{ + function GetAgentPaymentForContract(Contract $contract) + { + $agent = $contract->deal->agent; + $agentPaymentable = $agent->getPaymentable($contract->deal->complex); + $rewardPercent = $agentPaymentable->getPaymentablePercent(); + if (!$rewardPercent) + { + $rewardPercent = 0; + } + $price = $contract->price; + return ($price * $rewardPercent) / 100; + } } \ No newline at end of file diff --git a/app/Modules/Contracts/Http/Controllers/ContractsController.php b/app/Modules/Contracts/Http/Controllers/ContractsController.php index ab3b12a..39e168c 100644 --- a/app/Modules/Contracts/Http/Controllers/ContractsController.php +++ b/app/Modules/Contracts/Http/Controllers/ContractsController.php @@ -44,4 +44,11 @@ public function delete(Contract $contract) } return back()->withErrors('Не удалось корректно удалить договор и сделку. Попробуйте позже.'); } + + public function comment(Request $request, Contract $contract) + { + $contract->comment = $request->comment; + $contract->save(); + return back()->with('success', 'Комментарий к договору сохранен'); + } } \ No newline at end of file diff --git a/app/Modules/Contracts/Http/Livewire/ContractsTableLivewire.php b/app/Modules/Contracts/Http/Livewire/ContractsTableLivewire.php index e173c44..17fd6e4 100644 --- a/app/Modules/Contracts/Http/Livewire/ContractsTableLivewire.php +++ b/app/Modules/Contracts/Http/Livewire/ContractsTableLivewire.php @@ -3,15 +3,15 @@ namespace Modules\Contracts\Http\Livewire; use Livewire\Component; -use App\Models\Company\Company; -use App\Models\Complex; -use App\Models\Agent\Agent; +use Modules\Main\Models\Company\Company; +use Modules\Main\Models\Complex; +use Modules\Main\Models\Agent\Agent; use App\Models\Deal\Deal; -use App\Models\Deal\Contract; +use Modules\Contracts\Models\Contract; use App\Models\Deal\ContractStatus; use App\Models\User\UserRole; use App\Models\User\Role; -use App\Models\Company\CompanyAdmin; +use Modules\Main\Models\Company\CompanyAdmin; class ContractsTableLivewire extends Component { diff --git a/app/Modules/Contracts/Routes/web.php b/app/Modules/Contracts/Routes/web.php index 86a674d..b8f2cfb 100644 --- a/app/Modules/Contracts/Routes/web.php +++ b/app/Modules/Contracts/Routes/web.php @@ -7,5 +7,7 @@ { Route::any('/contracts', [ContractsController::class, 'index'])->name('contracts'); Route::post('/contracts/{contract}/delete', [ContractsController::class, 'delete'])->name('contract.delete'); + Route::post('/contracts/{contract}/comment', [ContractsController::class, 'comment'])->name('contract.comment'); + }); \ No newline at end of file diff --git a/app/Modules/Contracts/Views/livewire/table/index.blade.php b/app/Modules/Contracts/Views/livewire/table/index.blade.php index 1562274..1e25b52 100644 --- a/app/Modules/Contracts/Views/livewire/table/index.blade.php +++ b/app/Modules/Contracts/Views/livewire/table/index.blade.php @@ -41,14 +41,7 @@ deal->agent; - $agentPaymentable = $agent->getPaymentable($contract->deal->complex); - $rewardPercent = $agentPaymentable->getPaymentablePercent(); - if (!$rewardPercent) { - $rewardPercent = 0; - } - $price = $contract->price; - $contract->reward = ($price * $rewardPercent) / 100; + $contract->reward = GetAgentPaymentForContract($contract); //$contract->reward = $contract->reward ? $contract->reward : 0; $reward = Number::forHumans($contract->reward, precision: 2); $reward = str_replace('million', 'млн', $reward); @@ -61,7 +54,7 @@ {!! $reward !!} @else + title='Вознаграждение будет зафиксировано при изменении статуса на "Выплачено"'> {!! $reward !!} @endif @@ -84,7 +77,7 @@
@csrf - +
diff --git a/app/Modules/Main/Config/config.php b/app/Modules/Main/Config/config.php new file mode 100644 index 0000000..ce09543 --- /dev/null +++ b/app/Modules/Main/Config/config.php @@ -0,0 +1,5 @@ +id(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('mains'); + } +}; diff --git a/app/Modules/Main/Http/Controllers/MainController.php b/app/Modules/Main/Http/Controllers/MainController.php new file mode 100644 index 0000000..b579f6b --- /dev/null +++ b/app/Modules/Main/Http/Controllers/MainController.php @@ -0,0 +1,17 @@ +belongsTo(Company::class); + } protected static function booted(): void - { + { static::created(function (CompanyAdmin $admin) - { + { UserRole::create([ 'user_id' => $admin->user_id, 'role_id' => Role::COMPANY_ADMIN ]); - }); + }); static::deleted(function (CompanyAdmin $admin) - { + { UserRole::where([ 'user_id' => $admin->user_id, 'role_id' => Role::COMPANY_ADMIN ])->delete(); - }); + }); - } } +} diff --git a/app/Models/Company/CompanyStatus.php b/app/Modules/Main/Models/Company/CompanyStatus.php similarity index 79% rename from app/Models/Company/CompanyStatus.php rename to app/Modules/Main/Models/Company/CompanyStatus.php index d4463c5..c468604 100644 --- a/app/Models/Company/CompanyStatus.php +++ b/app/Modules/Main/Models/Company/CompanyStatus.php @@ -1,5 +1,5 @@ belongsTo(\App\Models\City::class, 'city_id')->withTrashed(); + return $this->belongsTo(City::class, 'city_id')->withTrashed(); } } diff --git a/app/Modules/Main/Models/Main.php b/app/Modules/Main/Models/Main.php new file mode 100644 index 0000000..905e7ba --- /dev/null +++ b/app/Modules/Main/Models/Main.php @@ -0,0 +1,11 @@ +app->register(RouteServiceProvider::class); + } + + public function boot() + { + $this->registerViews(); + $this->registerLivewireViews(); + $this->registerMigrations(); + $this->registerConfig(); + $this->registerComponent(); + $this->registerLivewire(); + } + + protected function registerViews() + { + $moduleViewsPath = __DIR__.'/../Views'; + $this->loadViewsFrom( + $moduleViewsPath, strtolower($this->moduleName) + ); + } + + protected function registerLivewireViews() + { + $moduleViewsPath = __DIR__.'/../Views/livewire'; + $this->loadViewsFrom( + $moduleViewsPath, strtolower($this->moduleName) + ); + } + + protected function registerMigrations() + { + $this->loadMigrationsFrom( + app_path('Modules/'.$this->moduleName.'/Database/Migrations') + ); + } + + protected function registerConfig() + { + $path = app_path('Modules/'.$this->moduleName.'/Config/config.php'); + $this->mergeConfigFrom( + $path, strtolower($this->moduleName) + ); + } + + protected function registerLivewire() + { + //Livewire::component('', \Modules\\Http\Livewire\::class); + } + + protected function registerComponent() + { + //Blade::component('', \Modules\\Http\Components\::class); + } +} \ No newline at end of file diff --git a/app/Modules/Main/Providers/RouteServiceProvider.php b/app/Modules/Main/Providers/RouteServiceProvider.php new file mode 100644 index 0000000..ec964d6 --- /dev/null +++ b/app/Modules/Main/Providers/RouteServiceProvider.php @@ -0,0 +1,24 @@ +registerWebRoutes(); + } + + protected function registerWebRoutes() + { + //Add Web Routes with web Guard + Route::middleware('web') + //Set Default Controllers Namespace + ->namespace('Modules\\Main\\Http\\Controllers') + ->group(app_path('Modules/Main/Routes/web.php')); + } +} \ No newline at end of file diff --git a/app/Modules/Main/Routes/web.php b/app/Modules/Main/Routes/web.php new file mode 100644 index 0000000..b9af2f2 --- /dev/null +++ b/app/Modules/Main/Routes/web.php @@ -0,0 +1,13 @@ +group(function() { + + Route::get('/main', [MainController::class, 'index']); + + Route::middleware(['hasAccess'])->group(function() { + /** Routes that need to be protected - Маршруты которые нужно защитить */ + }); +}); \ No newline at end of file diff --git a/app/Modules/Main/Views/index.blade.php b/app/Modules/Main/Views/index.blade.php new file mode 100644 index 0000000..f8198cf --- /dev/null +++ b/app/Modules/Main/Views/index.blade.php @@ -0,0 +1,4 @@ +@extends('layouts.app') + @section('content') +

Example views

+ @endsection \ No newline at end of file diff --git a/app/Modules/Payment/Models/Payment.php b/app/Modules/Payment/Models/Payment.php index dfb7cc6..4fa1369 100644 --- a/app/Modules/Payment/Models/Payment.php +++ b/app/Modules/Payment/Models/Payment.php @@ -4,9 +4,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use App\Models\Agent\Agent; -use App\Models\Company\Company; -use App\Models\Complex; +use Modules\Main\Models\Agent\Agent; +use Modules\Main\Models\Company\Company; +use Modules\Main\Models\Complex; class Payment extends Model { use HasFactory; diff --git a/app/Modules/Payment/Traits/Paymentable.php b/app/Modules/Payment/Traits/Paymentable.php index 9fd5f35..f2f7b86 100644 --- a/app/Modules/Payment/Traits/Paymentable.php +++ b/app/Modules/Payment/Traits/Paymentable.php @@ -3,7 +3,7 @@ namespace Modules\Payment\Traits; use Illuminate\Http\Request; use Modules\Payment\Models\Payment; -use App\Models\Complex; +use Modules\Main\Models\Complex; trait Paymentable { private $defaultValue = -1; // -1 || null diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index af85851..4b5c045 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -24,11 +24,18 @@ public function register(): void { //Получить имя модуля из имени каталога $moduleName = basename($moduleDirectory); - $providerClassName = '\\Modules\\' . $moduleName . '\\Providers\\ModuleServiceProvider'; - if (class_exists($providerClassName)) + try { - //Зарегистрировать поставщика услуг модуля, если он существует - $this->app->register($providerClassName); + $providerClassName = '\\Modules\\' . $moduleName . '\\Providers\\ModuleServiceProvider'; + if (class_exists($providerClassName)) + { + //Зарегистрировать поставщика услуг модуля, если он существует + $this->app->register($providerClassName); + } + } + catch (\Exception $e) + { + dd($e); } } } diff --git a/resources/views/clients/contract/index.blade.php b/resources/views/clients/contract/index.blade.php index 85acb5e..f1b8ab3 100644 --- a/resources/views/clients/contract/index.blade.php +++ b/resources/views/clients/contract/index.blade.php @@ -36,21 +36,6 @@ class="bi bi-arrow-right" viewBox="0 0 16 16">
{{ $contract->deal->complex->name }}
-
@@ -60,7 +45,7 @@ class="bi bi-pen" viewBox="0 0 16 16">
Статус
- {{ __('contract status ' . strtolower($contract->status)) }} + {{ __('contracts.status_' . $contract->status) }}
@@ -70,18 +55,24 @@ class="bi bi-pen" viewBox="0 0 16 16">
-
-
Площадь объекта
-
{{ $contract->square }}
-
-
-
Этаж
-
{{ $contract->floor }}
-
-
-
Помещение
-
{{ $contract->room }}
-
+ @if ($contract->square) +
+
Площадь объекта
+
{{ $contract->square }}
+
+ @endif + @if ($contract->floor) +
+
Этаж
+
{{ $contract->floor }}
+
+ @endif + @if ($contract->room) +
+
Помещение
+
{{ $contract->room }}
+
+ @endif
@@ -96,15 +87,10 @@ class="bi bi-pen" viewBox="0 0 16 16">
Вознаграждение
- {{ number_format($contract->reward, 2, ',', ' ') }}
-
-
-
-
-
Комментарий к договору
-
{{ $contract->comment }}
+ {{ number_format(GetAgentPaymentForContract($contract), 2, ',', ' ') }}
+
+
+
+
+ Комментарий к договору + @if ($contract->comment) + + + + + + @endif +
+ @if ($contract->comment) +
{{ $contract->comment }}
+ @else +
Оставьте + комментарий, он будет виден + только вам
+ @endif +
+
История договора
@@ -155,6 +164,31 @@ class="bi bi-record-circle-fill align-middle" viewBox="0 0 16 16"> @endforeach @endif
+ + +