diff --git a/app/Modules/Admin/Http/Controllers/AdminBitrixController.php b/app/Modules/Admin/Http/Controllers/AdminBitrixController.php index 98af25a..e47cd4b 100644 --- a/app/Modules/Admin/Http/Controllers/AdminBitrixController.php +++ b/app/Modules/Admin/Http/Controllers/AdminBitrixController.php @@ -44,6 +44,7 @@ public function syncDeals(Agent $agent) $deals = json_decode($data, true); foreach ($deals as $deal) { + $inDeal = $deal['deal'];//входящие данные по сделке if (count($deal['contacts']) == 0) { continue; @@ -62,7 +63,7 @@ public function syncDeals(Agent $agent) } ; $dealItem = false; //собственный, не из битрикса - $bitrixId = BitrixId::where('bx_id', $deal['deal']['deal_id']) + $bitrixId = BitrixId::where('bx_id', $inDeal['deal_id']) ->where('bitrixable_type', Deal::class); //Загрузка сделок if ($bitrixId->count() == 0) @@ -80,8 +81,6 @@ public function syncDeals(Agent $agent) $bitrixId = $bitrixId->first(); $dealItem = Deal::find($bitrixId->bitrixable_id); } - ; - $inDeal = $deal['deal'];//входящие данные по сделке if ($dealItem) { $importedCount++; diff --git a/app/Modules/Contracts/Helpers/helper.php b/app/Modules/Contracts/Helpers/helper.php new file mode 100644 index 0000000..0d12600 --- /dev/null +++ b/app/Modules/Contracts/Helpers/helper.php @@ -0,0 +1,16 @@ + ContractStatus::getName(ContractStatus::NEW), + ContractStatus::RESERVATION => ContractStatus::getName(ContractStatus::RESERVATION), + ContractStatus::SUCCESS => ContractStatus::getName(ContractStatus::SUCCESS), + ContractStatus::DECLINE => ContractStatus::getName(ContractStatus::DECLINE), + ContractStatus::TREATY => ContractStatus::getName(ContractStatus::TREATY), + ]; + } +} \ 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 a87369b..dceafce 100644 --- a/app/Modules/Contracts/Http/Controllers/ContractsController.php +++ b/app/Modules/Contracts/Http/Controllers/ContractsController.php @@ -10,10 +10,23 @@ class ContractsController extends Controller { - public function index() + public function index(Request $request) { + $mode = 'all'; + $filter = []; + + if ($request->exists('mode')) + { + $mode = $request->mode; + } + if ($request->exists('filter')) + { + $filter = $request->filter; + } + return view('contracts::index', [ - 'status' => 'all' + 'mode' => $mode, + 'filter' => $filter ]); } @@ -25,7 +38,6 @@ public function delete(Contract $contract) if ($deal->delete()) { return back()->with('success', 'Договор был успешно удален из базы данных'); - } } return back()->withErrors('Не удалось корректно удалить договор и сделку. Попробуйте позже.'); diff --git a/app/Modules/Contracts/Http/Livewire/ContractsTableLivewire.php b/app/Modules/Contracts/Http/Livewire/ContractsTableLivewire.php index c982d62..da2a96a 100644 --- a/app/Modules/Contracts/Http/Livewire/ContractsTableLivewire.php +++ b/app/Modules/Contracts/Http/Livewire/ContractsTableLivewire.php @@ -15,6 +15,8 @@ class ContractsTableLivewire extends Component { + public $mode = false; + public $filter = []; public function mount() { @@ -37,17 +39,48 @@ function getSelectingAgents() return [$agent->id]; } } - public function render() - { + private function getContracts() + { $contracts = Contract::whereHas('deal', function ($dealSubQuery) { $dealSubQuery->with('deals') ->whereIn('agent_id', $this->getSelectingAgents()); }); + $this->appendMode($contracts); + $this->appendFilter($contracts); + return $contracts->get(); + } + private function appendMode(&$query) + { + if ($this->mode == 'active') + { + $query->whereIn('status', [ + ContractStatus::NEW , + ContractStatus::RESERVATION, + ContractStatus::SUCCESS, + ]); + } + if ($this->mode == 'finished') + { + $query->whereIn('status', [ + ContractStatus::DECLINE, + ContractStatus::TREATY + ]); + } + } + private function appendFilter(&$query) + { + foreach ($this->filter as $fKey => $fValue) + { + $query->where($fKey, $fValue); + } + } + public function render() + { return view('contracts::livewire.table.index', [ - 'contracts' => $contracts->get(), + 'contracts' => $this->getContracts(), 'statuses' => ContractStatus::class ]); } diff --git a/app/Modules/Contracts/Providers/ModuleServiceProvider.php b/app/Modules/Contracts/Providers/ModuleServiceProvider.php index c7a5e6d..1c0dcab 100644 --- a/app/Modules/Contracts/Providers/ModuleServiceProvider.php +++ b/app/Modules/Contracts/Providers/ModuleServiceProvider.php @@ -23,6 +23,7 @@ public function boot() $this->registerConfig(); $this->registerComponent(); $this->registerLivewire(); + $this->registerHelpers(); } protected function registerViews() @@ -69,4 +70,13 @@ 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/Contracts/Routes/web.php b/app/Modules/Contracts/Routes/web.php index e0c056b..86a674d 100644 --- a/app/Modules/Contracts/Routes/web.php +++ b/app/Modules/Contracts/Routes/web.php @@ -5,7 +5,7 @@ Route::middleware(['auth'])->group(function () { - Route::get('/contracts', [ContractsController::class, 'index'])->name('contracts'); + Route::any('/contracts', [ContractsController::class, 'index'])->name('contracts'); Route::post('/contracts/{contract}/delete', [ContractsController::class, 'delete'])->name('contract.delete'); }); \ No newline at end of file diff --git a/app/Modules/Contracts/Views/index.blade.php b/app/Modules/Contracts/Views/index.blade.php index 8e65828..eaa0790 100644 --- a/app/Modules/Contracts/Views/index.blade.php +++ b/app/Modules/Contracts/Views/index.blade.php @@ -1,45 +1,64 @@ @extends('layouts.app') @section('content') -
-
+ +
- - + + - - + + + + +
-
- + +