Skip to content

Commit

Permalink
Merge pull request #913 from bakaphp/feat-agent-owner-id
Browse files Browse the repository at this point in the history
Merge pull request #882 from bakaphp/hotfix-attribute-millage
  • Loading branch information
kaioken authored Feb 8, 2024
2 parents 89e359b + f077578 commit 7b73f40
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/Domains/Connectors/Zoho/Workflows/ZohoAgentActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,8 @@ public function execute(Model $user, AppInterface $app, array $params): array
protected function createAgent(AppInterface $app, ZohoService $zohoService, UserInterface $user, Companies $company): array
{
try {
$sponsorsPage = $company->get('sponsors_page') ?? [];
$userInvite = UsersInvite::fromCompany($company)->fromApp($app)->where('email', $user->email)->firstOrFail();
$agentPage = $user->get('agent_website');
$agentPageUserId = $sponsorsPage[$agentPage] ?? null;

$agentOwnerUserId = $agentPageUserId ?? $userInvite->users_id;
$agentOwner = Agent::fromCompany($company)->where('users_id', $agentOwnerUserId)->firstOrFail();
$agentOwner = Agent::fromCompany($company)->where('users_id', $userInvite->users_id)->firstOrFail();
$ownerInfo = $zohoService->getAgentByMemberNumber((string) $agentOwner->member_id);

$ownerId = $ownerInfo->Owner['id'];
Expand All @@ -112,6 +107,22 @@ protected function createAgent(AppInterface $app, ZohoService $zohoService, User
$ownerMemberNumber = null;
}

$sponsorsPage = $company->get('sponsors_page') ?? [];
$agentPage = $user->get('agent_website');
$agentPageUserId = $sponsorsPage[$agentPage] ?? null;
//@todo this is ugly , testing it out
if ($agentPageUserId) {
try {
$agentOwner = Agent::fromCompany($company)->where('users_id', $agentPageUserId)->firstOrFail();
$ownerMemberNumber = $agentOwner->member_id;
$ownerId = $agentOwner->users_linked_source_id;
} catch(Exception $e) {
$agentOwner = null;
$ownerInfo = null;
$ownerMemberNumber = null;
}
}

$companyDefaultOwnerSourceId = $company->get(CustomFieldEnum::ZOHO_USER_OWNER_ID->value);
$companyDefaultOwnerMemberId = $company->get(CustomFieldEnum::ZOHO_USER_OWNER_MEMBER_NUMBER->value) ?? 1001;
$agent = new Agent();
Expand Down

0 comments on commit 7b73f40

Please sign in to comment.