![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/medad.corals.io/Corals/modules/Medad/Services/ |
<?php namespace Corals\Modules\Medad\Services; use Corals\Foundation\Services\BaseServiceClass; use Corals\Modules\Medad\Facades\Medad; use Corals\Modules\Medad\Models\Company; use Corals\Modules\Medad\Models\CompanyRelation; use Corals\Modules\Medad\Models\CompanyRelationBranch; use Corals\Modules\Medad\Models\Invitation; use Corals\User\Models\User; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Str; class CompanyService extends BaseServiceClass { public function postStore($request, &$additionalData) { $company = $this->model; $company->update(['parent_id' => $company->id]); } public function postStoreUpdate($request, &$additionalData) { $company = $this->model; if (user()->can('admin', Company::class)) { $admins = $request->get('admins', []); $company->admins()->sync(array_combine($admins, array_map(function ($adminId) { return ['is_admin' => 1]; }, $admins))); } Artisan::call('cache:clear'); } public function storeRelation($request, $company) { $secondCompany = Company::findOrFail($request['company_id']); $companyRelation = CompanyRelation::create([ 'second_company_id' => $secondCompany->id, 'relation_type' => $request['relation_type'], 'company_id' => $company->id ]); $inverseRelationType = Medad::getCompanyOppositeType($request['relation_type']); CompanyRelation::create([ 'second_company_id' => $company->id, 'relation_type' => $inverseRelationType, 'company_id' => $secondCompany->id, ]); $branches = $request->get('branches', []); $branchesInsert = []; foreach ($branches as $branchId) { $branchesInsert[] = [ 'branch_id' => $branchId, 'company_relation_id' => $companyRelation->id, ]; } CompanyRelationBranch::query()->insert($branchesInsert); if ($companyRelation) { event('notifications.medad.added_company_relation', [ 'secondCompany' => $secondCompany, 'company' => $company, ]); } } public function storeNewCompanyFromRelation($request) { $company = Company::query()->create([ 'code' => $request['code'], 'name' => $request['name'], 'phone_number' => $request['phone_number'], 'email' => $request['email'], 'type' => Medad::getCompanyOppositeType(), 'status' => 'pending', ]); $company->update(['parent_id' => $company->id]); $token = Str::random(32); $invitation = Invitation::query()->create([ 'company_id' => $company->id, 'token' => $token, ]); event('notifications.medad.new_company_created', [ 'company' => $company, ]); event('notifications.medad.invite_new_company', [ 'company' => $company, 'invitation' => $invitation, ]); return $company; } public function updateCompanyRelation($request, $companyRelation = null) { $companyRelation->branches()->delete(); $branchFromRequest = $request->get('branches', []); foreach ($branchFromRequest as $branchId) { CompanyRelationBranch::create([ 'branch_id' => $branchId, 'company_relation_id' => $companyRelation->id, ]); } } public function storeNewCompanyAdmin(User $user, $token) { $invitation = Invitation::where('token', $token)->firstOrFail(); $company = $invitation->company; $company->admins()->sync([$user->id => ['is_admin' => 1]]); $invitation->delete(); } }