protected function onSuccess(ClientAccount $account, $withMaritalStatus) { /** @var AccountOwnerInterface $data */ $data = $this->form->getData(); $isPrimaryApplicant = $data instanceof UserAccountOwnerAdapter; if (true === $withMaritalStatus && $isPrimaryApplicant) { /** @var $profile Profile */ $profile = $account->getClient()->getProfile(); $spouse = $account->getClient()->getSpouse(); $maritalStatus = $this->form->get('marital_status')->getData(); if ($maritalStatus == Profile::CLIENT_MARITAL_STATUS_MARRIED) { if (!$spouse) { $spouse = new ClientAdditionalContact(); $spouse->setClient($account->getClient()); $spouse->setType(ClientAdditionalContact::TYPE_SPOUSE); } if ($this->form->has('spouse_first_name')) { $spouse->setFirstName($this->form->get('spouse_first_name')->getData()); } if ($this->form->has('spouse_middle_name')) { $spouse->setMiddleName($this->form->get('spouse_middle_name')->getData()); } if ($this->form->has('spouse_last_name')) { $spouse->setLastName($this->form->get('spouse_last_name')->getData()); } if ($this->form->has('spouse_birth_date')) { $spouse->setBirthDate($this->form->get('spouse_birth_date')->getData()); } } $profile->setMaritalStatus($maritalStatus); $this->em->persist($profile); } $account->setStepAction($isPrimaryApplicant ? ClientAccount::STEP_ACTION_PERSONAL : ClientAccount::STEP_ACTION_ADDITIONAL_PERSONAL); $account->setIsPreSaved($this->request->isXmlHttpRequest()); $this->em->persist($data->getObjectToSave()); $this->em->persist($account); $this->em->flush(); }
/** * @param TokenInterface $token * @param ClientAccount $object * @param array $attributes * @return int */ public function vote(TokenInterface $token, $object, array $attributes) { if (!$object instanceof ClientAccount) { return VoterInterface::ACCESS_ABSTAIN; } $user = $token->getUser(); if (!$user instanceof User) { return VoterInterface::ACCESS_ABSTAIN; } if ($user->isAdmin()) { return VoterInterface::ACCESS_GRANTED; } if (in_array($attributes[0], array(static::PERMISSION_CHANGE_CONSOLIDATOR, static::PERMISSION_APPROVE_BILL, static::PERMISSION_EDIT))) { if ($user == $object->getClient()->getRia()) { return VoterInterface::ACCESS_GRANTED; } } return VoterInterface::ACCESS_ABSTAIN; }
/** * Set account_id for owners in $this->owners array * * @param ClientAccount $account */ protected function saveAccountOwners(ClientAccount $account) { $ownerTypes = $this->getOwnerTypes(); if (empty($ownerTypes) && $account->getAccountOwners()->isEmpty()) { $owner = new ClientAccountOwner(); $owner->setOwnerType(ClientAccountOwner::OWNER_TYPE_SELF); $owner->setClient($account->getClient()); $owner->setAccount($account); $this->em->persist($owner); $this->em->flush(); } else { foreach ($account->getAccountOwners() as $accountOwner) { $this->em->remove($accountOwner); } foreach ($ownerTypes as $type) { $this->createAccountOwnerByType($account, $type); } $this->em->persist($account); $this->em->flush(); } }
/** * Set account_id for owners in $this->owners array * * @param ClientAccount $account */ protected function saveAccountOwners(ClientAccount $account) { if (empty($this->owners) && $account->getAccountOwners()->isEmpty()) { $owner = new ClientAccountOwner(); $owner->setOwnerType(ClientAccountOwner::OWNER_TYPE_SELF); $owner->setClient($account->getClient()); $owner->setAccount($account); $account->addAccountOwner($owner); $this->em->persist($owner); } else { $repo = $this->em->getRepository('WealthbotClientBundle:ClientAccountOwner'); foreach ($this->owners as $ownerItem) { $owner = new ClientAccountOwner(); $owner->setOwnerType($ownerItem['owner_type']); $owner->setAccount($account); if ($ownerItem['owner_type'] === ClientAccountOwner::OWNER_TYPE_SELF) { $client = $this->em->getRepository('WealthbotUserBundle:User')->find($ownerItem['owner_client_id']); if ($client) { $exist = $repo->findOneBy(array('owner_type' => $ownerItem['owner_type'], 'owner_client_id' => $client->getId(), 'account_id' => $account->getId())); if (!$exist) { $owner->setClient($client); $this->em->persist($owner); } } } else { $contact = $this->em->getRepository('WealthbotClientBundle:ClientAdditionalContact')->find($ownerItem['owner_contact_id']); if ($contact) { $exist = $repo->findOneBy(array('owner_type' => $ownerItem['owner_type'], 'owner_contact_id' => $contact->getId(), 'account_id' => $account->getId())); if (!$exist) { $owner->setContact($contact); $this->em->persist($owner); } } } $account->addAccountOwner($owner); } } $this->em->persist($account); $this->em->flush(); }
/** * * @SecureParam(name="account", permissions="CHANGE_CONSOLIDATOR") * @ParamConverter("account", class="WealthbotClientBundle:ClientAccount") * * @param ClientAccount $account * @param Request $request * @return \Symfony\Component\HttpFoundation\JsonResponse */ public function updateAccountsPaysForAction(ClientAccount $account, Request $request) { $number = $request->get('paysFor'); $em = $this->getDoctrine()->getManager(); if ($number == '') { $account->setConsolidator(null); } else { $consolidateAccount = $em->getRepository('WealthbotClientBundle:ClientAccount')->getByAccountNumber($number); $ria = $this->getUser(); if ($consolidateAccount->getClient()->getRia() !== $ria) { throw new AccessDeniedException('Consolidate account do not belongs to Your RIA'); } if ($consolidateAccount->getClient() !== $account->getClient()) { throw new AccessDeniedException('Consolidate account do not belongs to client'); } $account->setConsolidator($consolidateAccount); } $em->flush(); return new JsonResponse(array()); }
/** * Find new consolidator for accounts by old consolidator account object * * @param ClientAccount $oldConsolidator * @return null|ClientAccount */ public function findNewConsolidatorForAccounts(ClientAccount $oldConsolidator) { $clientId = $oldConsolidator->getClientId() ? $oldConsolidator->getClientId() : $oldConsolidator->getClient()->getId(); return $this->findNewConsolidatorByClientIdAndSystemTypeAndOwner($clientId, $oldConsolidator->getSystemType(), $oldConsolidator->getOwner(), $oldConsolidator->getId()); }
/** * Get wealthbot.io fee * * @param ClientAccount $clientAccount * @param integer $year * @param integer $quarter * @return float */ public function getCEFee(ClientAccount $clientAccount, $year, $quarter) { $ria = $clientAccount->getClient()->getRia(); $fees = $this->getAdminFee($ria); $period = $this->periodManager->getPeriod($year, $quarter); $value = $this->cashManager->getAccountValueOnDate($clientAccount, $period['endDate']); return $this->calculateFee($value, $fees); }
/** * Return new system account with client, client account, account number and account description * * @param ClientAccount $clientAccount * @return SystemAccount */ private function createAccount(ClientAccount $clientAccount) { // If system account is exist then update it $systemAccount = $clientAccount->getSystemAccount(); if (!$systemAccount) { $systemAccount = new SystemAccount(); } $systemAccount->setClient($clientAccount->getClient()); $systemAccount->setClientAccount($clientAccount); $systemAccount->setType($clientAccount->getSystemType()); $systemAccount->setAccountNumber('CE-000-' . rand(100000000, 999999999)); $systemAccount->setAccountDescription($clientAccount->getOwnersAsString() . ' ' . $clientAccount->getTypeName()); return $systemAccount; }
/** * @param ClientAccount $account * @param $year * @param $quarter * @param bool $flush * @throws \Exception */ public function approveAccount(ClientAccount $account, $year, $quarter, $flush = false) { $client = $account->getClient(); /** @var Bill $bill */ if (!($bill = $this->em->getRepository('WealthbotClientBundle:Bill')->findByClientAndPeriod($client, $year, $quarter))) { throw new \Exception('Bill was not generated'); //todo: make custom exception } $bill->setApprovedAt(new \DateTime()); if ($billItem = $this->em->getRepository('WealthbotClientBundle:BillItem')->getByAccountAndPeriod($account, $year, $quarter)) { $billItem->getStatus() == BillItem::STATUS_BILL_GENERATED && $billItem->setStatus(BillItem::STATUS_BILL_APPROVED); } else { return false; } $flush && $this->em->flush(); return true; }
public function sendClientRolloverInstruction401Email(ClientAccount $account, $rolloverMessage) { $template = $this->parameters['template']['client_rollover_instruction_401']; $client = $account->getClient(); $ria = $client->getRia(); $context = array('account' => $account, 'ria' => $ria, 'rollover_message' => $rolloverMessage, 'logo' => $this->getRiaLogo($ria->getId())); $this->sendMessage($template, $this->parameters['from_email']['client_rollover_instruction_401'], $client->getEmail(), $context); }