diff --git a/app/Models/Agent/Agent.php b/app/Models/Agent/Agent.php index 28d83cd..fd9d9f3 100644 --- a/app/Models/Agent/Agent.php +++ b/app/Models/Agent/Agent.php @@ -15,10 +15,13 @@ use App\Notifications\AgentCreated; +use Modules\Payment\Traits\Paymentable; + class Agent extends Model { use HasFactory; use SoftDeletes; + use Paymentable; public const STATUS_ACTIVE = "ACTIVE"; public const STATUS_DISMISSED = "DISMISSED"; protected $fillable = [ diff --git a/app/Models/Company/Company.php b/app/Models/Company/Company.php index f08409a..989417c 100644 --- a/app/Models/Company/Company.php +++ b/app/Models/Company/Company.php @@ -4,12 +4,12 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; - +use Modules\Payment\Traits\Paymentable; class Company extends Model - { +{ use HasFactory; - - const STATUS_NEW = 'new'; + use Paymentable; + const STATUS_NEW = 'new'; const STATUS_ACCEPTED = 'accepted'; const STATUS_DECLINED = 'declined'; protected $fillable = [ @@ -27,6 +27,6 @@ class Company extends Model protected $casts = [ 'details' => 'array', - 'type' => CompanyType::class + 'type' => CompanyType::class ]; - } +} diff --git a/app/Modules/Admin/Http/Controllers/AdminPaymentsController.php b/app/Modules/Admin/Http/Controllers/AdminPaymentsController.php index cff92d4..1aef011 100644 --- a/app/Modules/Admin/Http/Controllers/AdminPaymentsController.php +++ b/app/Modules/Admin/Http/Controllers/AdminPaymentsController.php @@ -8,19 +8,12 @@ use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use App\Models\Company\Company; -use App\Models\Complex; -use App\Models\Agent\Agent; class AdminPaymentsController extends Controller { public function index() { - return view('admin::payments.index', [ - 'companies' => Company::orderBy('name')->get(), - 'complexes' => Complex::orderBy('name')->get(), - 'agents' => Agent::all() - ]); + return view('admin::payments.index'); } } diff --git a/app/Modules/Admin/Http/Livewire/Payments.php b/app/Modules/Admin/Http/Livewire/Payments.php new file mode 100644 index 0000000..f015c87 --- /dev/null +++ b/app/Modules/Admin/Http/Livewire/Payments.php @@ -0,0 +1,80 @@ +companyId = $company->id; + } + + public function back() + { + $this->companyId = null; + } + + public function setPaymentValueForCompany(Company $company, Complex $complex) + { + $company->setPayment($complex, $this->value); + $this->value = null; + } + + public function unsetPaymentForCompany(Company $company, Complex $complex) + { + $company->unsetPayment($complex); + } + + public function setPaymentValueForAgent(Agent $agent, Complex $complex) + { + $agent->setPayment($complex, $this->value); + $this->value = null; + } + + public function setPaymentAsParentForAgent(Agent $agent, Complex $complex) + { + $agent->setAsParentPayment($complex); + $this->value = null; + } + + public function unsetPaymentForAgent(Agent $agent, Complex $complex) + { + $agent->unsetPayment($complex); + } + + public function render() + { + if ($this->companyId) + { + return view('admin::payments.agents', [ + 'company' => Company::find($this->companyId), + 'complexes' => Complex::orderBy('name')->get(), + 'agents' => Agent::where('company_id', $this->companyId)-> + with([ + 'user' => function ($query) + { + $query->orderBy('name', 'desc'); + } + ])->get() + ]); + } + else + { + return view('admin::payments.companies', [ + 'companies' => Company::orderBy('name')->get(), + 'complexes' => Complex::orderBy('name')->get(), + ]); + } + } +} \ No newline at end of file diff --git a/app/Modules/Admin/Providers/ModuleServiceProvider.php b/app/Modules/Admin/Providers/ModuleServiceProvider.php index 378e6e6..e803811 100644 --- a/app/Modules/Admin/Providers/ModuleServiceProvider.php +++ b/app/Modules/Admin/Providers/ModuleServiceProvider.php @@ -63,6 +63,8 @@ protected function registerLivewire() { Livewire::component('admin.menu', \Modules\Admin\Http\Livewire\AdminMenu::class); Livewire::component('admin.posts', \Modules\Admin\Http\Livewire\Posts::class); + Livewire::component('admin.payments', \Modules\Admin\Http\Livewire\Payments::class); + } protected function registerComponent() diff --git a/app/Modules/Admin/Views/payments/agents.blade.php b/app/Modules/Admin/Views/payments/agents.blade.php new file mode 100644 index 0000000..a5616a5 --- /dev/null +++ b/app/Modules/Admin/Views/payments/agents.blade.php @@ -0,0 +1,124 @@ +
| Агент | + @foreach ($complexes as $complex) +
+ {{ $complex->name }}
+
+ @php($compPayment = $company->getPaymentable($complex))
+
+ @if ($compPayment->value === null)
+ Не установлено
+ @elseif($compPayment->value == -1)
+ Наследовать
+ @else
+ {{ $compPayment->value }} %
+ @endif
+
+
+ |
+ @endforeach
+
|---|---|
| + {{ $agent->user->name }} + | + @foreach ($complexes as $complex) + @php($paymentable = $agent->getPaymentable($complex)) +
+ @if ($paymentable->value == null)
+
+
+
+
+ @elseif($paymentable->value == -1)
+
+
+
+
+ @else
+
+
+
+
+ @endif
+ |
+ @endforeach
+
| Компания | + @foreach ($complexes as $complex) +{{ $complex->name }} + | + @endforeach ++ |
|---|---|---|
| + {{ $company->name }} + | + @foreach ($complexes as $complex) + @php($paymentable = $company->getPaymentable($complex)) +
+ @if ($paymentable->value == null)
+
+
+
+
+ @elseif($paymentable->value == -1)
+
+
+
+
+ @else
+
+
+
+
+ @endif
+ |
+ @endforeach
+ + + | +
| Компания | - @foreach ($complexes as $complex) -{{ $complex->name }}
- 0 %
-
- |
- @endforeach
-
|---|---|
| - {{ $company->name }} - | - @foreach ($complexes as $complex) -Наследовать | - @endforeach -