/
var
/
www
/
html
/
back
/
app
/
Services
/
Model
/
Upload File
HOME
<?php namespace App\Services\Model; use App\Http\Resources\AccountResource; use App\Http\Resources\CounterpartyResource; use App\Http\Resources\IntegrationResource; use App\Http\Resources\OrganizationResource; use App\Models\Integration; use App\Repositories\Model\Interfaces\ModelInterface; class ModelService { private ModelInterface $modelRepository; public function __construct(ModelInterface $repository) { $this->modelRepository = $repository; } public function getAccounts($modelId) { $accountsNotArchived = $this->modelRepository->getAccounts($modelId, false); $accountsArchived = $this->modelRepository->getAccounts($modelId, true); $cashAccounts = $this->modelRepository->getCashAccounts($modelId, true); return [ 'active' => [ 'count' => $accountsNotArchived->count(), 'data' => AccountResource::collection($accountsNotArchived), ], 'archived' => [ 'count' => $accountsArchived->count(), 'data' => AccountResource::collection($accountsArchived), ], 'cash' => [ 'count' => $cashAccounts->count(), 'data' => AccountResource::collection($cashAccounts), ], ]; } public function getCounterparties($modelId) { $counterpartiesNotArchived = $this->modelRepository->getCounterparties($modelId, false); $counterpartiesArchived = $this->modelRepository->getCounterparties($modelId, true); return [ 'active' => [ 'count' => $counterpartiesNotArchived->count(), 'data' => CounterpartyResource::collection($counterpartiesNotArchived), ], 'archived' => [ 'count' => $counterpartiesArchived->count(), 'data' => CounterpartyResource::collection($counterpartiesArchived), ], ]; } public function getOrganizations($modelId) { $organizationsNotArchived = $this->modelRepository->getOrganizations($modelId, false); $organizationsArchived = $this->modelRepository->getOrganizations($modelId, true); return [ 'active' => [ 'count' => $organizationsNotArchived->count(), 'data' => OrganizationResource::collection($organizationsNotArchived), ], 'archived' => [ 'count' => $organizationsArchived->count(), 'data' => OrganizationResource::collection($organizationsArchived), ], ]; } public function getIntegrations($modelId) { $integrationArchived = Integration::query()->where(['system_id' => $modelId, 'archived' => true])->get(); $integrationNotArchived = Integration::query()->where(['system_id' => $modelId, 'archived' => false])->get(); return [ 'active' => [ 'count' => $integrationNotArchived->count(), 'data' => IntegrationResource::collection($integrationNotArchived), ], 'archived' => [ 'count' => $integrationArchived->count(), 'data' => IntegrationResource::collection($integrationArchived), ], ]; } }