Example #1
0
 public function createBill(User $user, $dateStr, ObjectManager $manager)
 {
     $date = new \DateTime($dateStr);
     $period = $this->periodManager->getPreviousQuarter($date);
     $accounts = $user->getClientAccounts();
     $bill = new Bill();
     $bill->setCreatedAt(new \DateTime($dateStr));
     $bill->setClient($user);
     $bill->setYear($period['year']);
     $bill->setQuarter($period['quarter']);
     $manager->persist($bill);
     foreach ($accounts as $account) {
         $systemAccount = $account->getSystemAccount();
         if ($systemAccount) {
             $billItem = new BillItem();
             $billItem->setSystemAccount($systemAccount);
             $billItem->setBill($bill);
             $billItem->setFeeBilled($this->feeManager->getRiaFee($account, $period['year'], $period['quarter']));
             $billItem->setCreatedAt(new \DateTime($dateStr));
             $manager->persist($billItem);
         }
     }
     $manager->flush();
 }
 /**
  * Makes array of ClientAccount which must be used for Custodian Fee File generator.
  *
  * @param $riaUser
  * @param $selectedAccounts
  * @param $year
  * @param $quarter
  *
  * @return array
  * @throws \Exception
  */
 public function getAccountsForCustodianFeeFile($riaUser, $selectedAccounts, $year, $quarter)
 {
     $now = new \DateTime();
     $interval = new \DateInterval('P3D');
     $periods = $this->periodManager->getPeriod($year, $quarter);
     /* @var ClientAccountRepository $clientAccountRepo */
     $clientAccountRepo = $this->em->getRepository('WealthbotClientBundle:ClientAccount');
     $accounts = $clientAccountRepo->filterAccountsForCustodianFeeFile($riaUser, $selectedAccounts, $periods['endDate']);
     $firstAccount = reset($accounts);
     if ($firstAccount) {
         $approveDate = $this->summaryInformationManager->getClientBillApproveDate($firstAccount->getClient(), $year, $quarter);
         if ($now->sub($interval) < $approveDate) {
             throw new \Exception('You must wait 3 days after bill approval in order to create Custodian Fee File');
         }
     }
     return $accounts;
 }
 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;
 }
Example #4
0
 /**
  * @param int $year
  * @param int $quarter
  * @return array
  */
 public function getPeriod($year, $quarter)
 {
     return $this->periodManager->getPeriod($year, $quarter);
 }