public function getAccountValueOnDate(ClientAccount $account, \DateTime $date)
 {
     $systemAccount = $account->getSystemAccount();
     $v = 0;
     if ($systemAccount) {
         $v = $this->em->getRepository('WealthbotClientBundle:ClientAccountValue')->getSumBeforeDate($systemAccount, $date);
     }
     if ($v == 0) {
         $v = $account->getValue();
     }
     return $v;
 }
 /**
  * @param ClientAccount $account
  * @param $year
  * @param int $quarter
  * @return null|BillItem
  */
 public function getByAccountAndPeriod(ClientAccount $account, $year, $quarter = 0)
 {
     $systemAccount = $account->getSystemAccount();
     if (!$systemAccount) {
         return null;
     }
     $qb = $this->createQueryBuilder('i')->where('i.systemAccount = :systemAccount')->leftJoin('i.bill', 'b')->andWhere('b.year = :year')->setParameter('systemAccount', $systemAccount)->setParameter('year', $year)->setMaxResults(1);
     if ($quarter == 0) {
         $qb->orderBy('b.quarter', 'DESC');
     } else {
         $qb->andWhere('b.quarter = :quarter')->setParameter('quarter', $quarter);
     }
     return $qb->getQuery()->getOneOrNullResult();
 }
 /**
  * Build data for contribution form with one_time action
  *
  * @param ClientAccount $clientAccount
  * @param AccountContribution $existContribution
  * @return OneTimeContribution
  */
 private function buildOneTimeContributionData(ClientAccount $clientAccount, AccountContribution $existContribution = null)
 {
     $data = new OneTimeContribution();
     $data->setSystemAccount($clientAccount->getSystemAccount());
     if ($existContribution) {
         $data->setBankInformation($existContribution->getBankInformation());
         if ($existContribution->isOneTimeContribution()) {
             $data->setContributionYear($existContribution->getContributionYear());
             $data->setStartTransferDate($existContribution->getStartTransferDate());
             $data->setAmount($existContribution->getAmount());
         }
     }
     return $data;
 }
Beispiel #4
0
 /**
  * Get systemAccount
  *
  * @return \Wealthbot\ClientBundle\Entity\SystemAccount
  */
 public function getSystemAccount()
 {
     if (null === $this->systemAccount && $this->consolidator) {
         return $this->consolidator->getSystemAccount();
     }
     return $this->systemAccount;
 }
 /**
  * @SecureParam(name="account", permissions="EDIT")
  * @ParamConverter("account", class="WealthbotClientBundle:ClientAccount", options={"id" = "account_id"})
  */
 public function accountSettingsAction(ClientAccount $account, Request $request)
 {
     /** @var EntityManager $em */
     $em = $this->get('doctrine.orm.entity_manager');
     $systemAccount = $account->getSystemAccount();
     $form = $this->createForm(new AccountSettingsFormType($em), $account);
     $oneTimeDistribution = new Distribution();
     $oneTimeDistribution->setType(Distribution::TYPE_ONE_TIME);
     $oneTimeDistribution->setSystemClientAccount($systemAccount);
     $oneTimeDistributionForm = $this->createForm(new OneTimeDistributionFormType(), $oneTimeDistribution);
     $scheduledDistribution = $em->getRepository('WealthbotClientBundle:Distribution')->findOneBy(array('systemClientAccount' => $systemAccount, 'type' => Distribution::TYPE_SCHEDULED));
     if (null === $scheduledDistribution) {
         $scheduledDistribution = new Distribution();
         $scheduledDistribution->setType(Distribution::TYPE_SCHEDULED);
         $scheduledDistribution->setSystemClientAccount($systemAccount);
     }
     $scheduledDistributionForm = $this->createForm(new ScheduledDistributionFormType(), $scheduledDistribution);
     if ($request->isMethod('POST')) {
         $scheduledDistributionForm->bind($request);
         if ($scheduledDistributionForm->isValid()) {
             $scheduledDistributionFormData = $scheduledDistributionForm->getData();
             if ($scheduledDistributionFormData->getAmount() > 0) {
                 $em->persist($scheduledDistributionFormData);
                 $em->flush();
             }
         }
         $oneTimeDistributionForm->bind($request);
         if ($oneTimeDistributionForm->isValid()) {
             $oneTimeDistributionFormData = $oneTimeDistributionForm->getData();
             if ($oneTimeDistributionFormData->getAmount() > 0) {
                 $em->persist($oneTimeDistributionFormData);
                 $em->flush();
             }
         }
         $form->bind($request);
         if ($form->isValid()) {
             $formData = $form->getData();
             $em->persist($formData);
             $em->flush();
         }
     }
     return $this->render('WealthbotRiaBundle:Dashboard:account_settings.html.twig', array('scheduledDistributionForm' => $scheduledDistributionForm->createView(), 'oneTimeDistributionForm' => $oneTimeDistributionForm->createView(), 'form' => $form->createView()));
 }
Beispiel #6
0
 /**
  * TODO: deprecated
  * @param ClientAccount $clientAccount
  * @param $year
  * @param $quarter
  * @return float|int
  */
 public function getBillAmount(ClientAccount $clientAccount, $year, $quarter)
 {
     $repo = $this->em->getRepository('WealthbotClientBundle:ClientAccountValue');
     $period = $this->periodManager->getPeriod($year, $quarter);
     $systemAccount = $clientAccount->getSystemAccount();
     $accountValues = $repo->getAverageAccountValues($systemAccount, $period['startDate'], $period['endDate']);
     if ($accountValues['count_values']) {
         $lastDay = $repo->getLastDayByPeriod($systemAccount, $period['startDate'], $period['endDate']);
         $dayInPeriod = $period['endDate']->diff($period['startDate'])->format('%a');
         //TODO: ???
         $fee = $this->getRiaFee($clientAccount, $year, $quarter);
         //TODO: Formula (BillingSpec fee value) * (account value in last day of quarter) * (number of days when account was open) / (number of days in quarter)
         return $fee * $lastDay->getTotalValue() * $accountValues['count_values'] / $dayInPeriod;
     }
     return 0;
 }
 /**
  * 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;
 }
 /**
  * Returns array with:
  *  avg_value, count_values
  *
  * @param ClientAccount $account
  * @param \DateTime $dateFrom
  * @param \DateTime $dateTo
  * @return array
  */
 public function getAverageAccountValues(ClientAccount $account, \DateTime $dateFrom, \DateTime $dateTo)
 {
     $systemAccount = $account->getSystemAccount();
     if (!$systemAccount) {
         return array('avg_value' => 0, 'count_values' => 0);
     }
     $r = $this->createQueryBuilder('v')->select('AVG(v.total_value) as AV, COUNT(v.total_value) as CV')->where('v.systemClientAccount = :sysAccount')->andWhere('v.date >= :dateFrom')->andWhere('v.date < :dateTo')->orderBy('v.date', 'ASC')->setParameter('sysAccount', $systemAccount)->setParameter('dateFrom', $dateFrom)->setParameter('dateTo', $dateTo)->getQuery()->getArrayResult();
     if (count($r)) {
         return array('avg_value' => $r[0]['AV'], 'count_values' => $r[0]['CV']);
     } else {
         return array('avg_value' => 0, 'count_values' => 0);
     }
 }
Beispiel #9
0
 /**
  * @param ClientAccount $account
  * @param float $fee
  * @param int $year
  * @param int $quarter
  * @return float|int
  */
 public function calculateBillSumByPeriod(ClientAccount $account, $fee, $year, $quarter)
 {
     $period = $this->feeManager->getPeriod($year, $quarter);
     $systemAccount = $account->getSystemAccount();
     $accountValues = $this->em->getRepository('WealthbotClientBundle:ClientAccountValue')->getAverageAccountValues($account, $period['startDate'], $period['endDate']);
     $dayInPeriod = $period['endDate']->diff($period['startDate'])->format('%a');
     return $this->feeManager->calculateFeeBilled($fee, $accountValues['count_values'], $dayInPeriod);
 }
 public function getBillItemStatus(ClientAccount $account, $year, $quarter)
 {
     $period = $this->periodManager->getPeriod($year, $quarter);
     $systemAccount = $account->getSystemAccount();
     if (!$systemAccount) {
         return BillItem::STATUS_BILL_IS_NOT_APPLICABLE;
     }
     $activityCheck = $this->em->getRepository('WealthbotClientBundle:ClientAccountValue')->getFirstActivityDate($account);
     if (!$activityCheck || $activityCheck->getDate()->getTimestamp() >= $period['endDate']->getTimestamp()) {
         return BillItem::STATUS_BILL_IS_NOT_APPLICABLE;
     }
     /** @var BillItem $billItem */
     $billItem = $this->em->getRepository('WealthbotClientBundle:BillItem')->getByAccountAndPeriod($account, $year, $quarter);
     if ($billItem) {
         return $billItem->getStatus();
     }
     return BillItem::STATUS_BILL_NOT_GENERATED;
 }