/** * Create new one-time distribution * * @param SystemAccount $account * @return Distribution */ public function createOneTimeDistribution(SystemAccount $account) { $distribution = new Distribution(); $distribution->setSystemClientAccount($account); $distribution->setType(Distribution::TYPE_ONE_TIME); return $distribution; }
public function onPreSetData(FormEvent $event) { $form = $event->getForm(); if ($this->account->isRothIraType() || $this->account->isTraditionalIraType()) { $form->add($this->factory->createNamed('distribution_method', 'choice', null, array('choices' => Distribution::getDistributionMethodChoices(), 'expanded' => true, 'multiple' => false, 'required' => false)))->add($this->factory->createNamed('federal_withholding', 'choice', null, array('choices' => Distribution::getFederalWithholdingChoices(), 'expanded' => true, 'multiple' => false, 'required' => false)))->add($this->factory->createNamed('state_withholding', 'choice', null, array('choices' => Distribution::getStateWithholdingChoices(), 'expanded' => true, 'multiple' => false, 'required' => false)))->add($this->factory->createNamed('federal_withhold_percent', 'percent', null, array('required' => false)))->add($this->factory->createNamed('federal_withhold_money', 'number', null, array('precision' => 2, 'grouping' => true, 'required' => false)))->add($this->factory->createNamed('state_withhold_percent', 'percent', null, array('required' => false)))->add($this->factory->createNamed('state_withhold_money', 'number', null, array('precision' => 2, 'grouping' => true, 'required' => false)))->add($this->factory->createNamed('residenceState', 'entity', null, array('class' => 'WealthbotAdminBundle:State', 'label' => 'State', 'empty_value' => 'Select a State', 'required' => false))); } }
/** * Validate frequency field */ private function validateFrequency() { if ($this->form->has('frequency')) { $frequencyChoices = Distribution::getFrequencyChoices(); if (!in_array($this->data->getFrequency(), array_keys($frequencyChoices))) { $this->form->get('frequency')->addError(new FormError('Choose an option.')); } } }
public function buildForm(FormBuilderInterface $builder, array $options) { $distribution = $builder->getData(); if (null == $distribution->getFrequency()) { $distribution->setFrequency(Distribution::FREQUENCY_EVERY_OTHER_WEEK); } $this->factory = $builder->getFormFactory(); $builder->add('frequency', 'choice', array('expanded' => true, 'label' => 'Frequency of transaction: ', 'choices' => Distribution::getFrequencyChoices()))->add('amount', 'money', array('attr' => array('class' => 'input-mini'), 'currency' => 'USD', 'label' => 'Amount: ')); $builder->addEventListener(FormEvents::PRE_SET_DATA, array($this, 'onPreSetData')); $builder->addEventListener(FormEvents::BIND, array($this, 'onBindData')); }
/** * @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())); }
/** * Get choices for frequency field * * @return array */ protected function getFrequencyChoices() { return array_reverse(Distribution::getFrequencyChoices(), true); }
/** * Load data fixtures with the passed EntityManager * * @param \Doctrine\Common\Persistence\ObjectManager $manager */ function load(ObjectManager $manager) { $distribution = new Distribution(); $distribution->setType(Distribution::TYPE_SCHEDULED); $distribution->setSystemClientAccount($this->getReference('system-account')); $distribution->setBankInformation($this->getReference('bank-info')); $distribution->setResidenceState($this->getReference('state-Florida')); $distribution->setTransferMethod(Distribution::TRANSFER_METHOD_BANK_TRANSFER); $date = new \DateTime('2014-01-01'); $distribution->setTransferDate($date); $distribution->setAmount(500); $distribution->setFrequency(Distribution::FREQUENCY_MONTHLY); $distribution->setDistributionMethod(1); $distribution->setFederalWithholding(Distribution::FEDERAL_WITHHOLDING_TAXES); $distribution->setStateWithholding(Distribution::STATE_WITHHOLDING_TAXES); $distribution->setFederalWithholdPercent(0); $distribution->setFederalWithholdMoney(0); $distribution->setStateWithholdPercent(0); $distribution->setStateWithholdMoney(0); $manager->persist($distribution); $manager->flush(); }
/** * Validate state_withholding and child fields */ private function validateStateWithholding() { if ($this->form->has('state_withholding')) { $stateWithholding = $this->data->getStateWithholding(); if (!in_array($stateWithholding, array_keys(Distribution::getStateWithholdingChoices()))) { $this->form->get('state_withholding')->addError(new FormError('Choose an option.')); } elseif ($stateWithholding == Distribution::STATE_WITHHOLDING_TAXES) { $percentRate = $this->data->getStateWithholdPercent(); $moneyRate = $this->data->getStateWithholdMoney(); if (!is_numeric($percentRate) && !is_numeric($moneyRate)) { $this->form->get('state_withholding')->addError(new FormError('Please enter withhold taxes rate.')); } elseif (is_numeric($percentRate) && is_numeric($moneyRate)) { $this->form->get('state_withholding')->addError(new FormError('Please enter percent or money withhold taxes rate.')); } $this->data->setResidenceState(null); } elseif ($stateWithholding == Distribution::STATE_WITHHOLDING_RESIDENCE_STATE && !$this->data->getResidenceState()) { $this->form->get('residenceState')->addError(new FormError('Choose an option.')); $this->data->setStateWithholdPercent(null); $this->data->setStateWithholdMoney(null); } else { $this->data->setStateWithholdPercent(null); $this->data->setStateWithholdMoney(null); $this->data->setResidenceState(null); } } }
/** * Build data for one-time distribution form * * @param SystemAccount $account * @param Distribution $existDistribution * @return Distribution */ private function buildOneTimeDistributionData(SystemAccount $account, Distribution $existDistribution = null) { $data = $this->manager->createOneTimeDistribution($account); if ($existDistribution && $existDistribution->getBankInformation()) { $data->setBankInformation($existDistribution->getBankInformation()); } elseif ($account->getAccountContribution() && $account->getAccountContribution()->getBankInformation()) { $data->setBankInformation($account->getAccountContribution()->getBankInformation()); } return $data; }