/** * Gets a list of all phone numbers available for the given Opportunity object * * @param Opportunity $object * * @return array of [phone number, phone owner] */ public function getPhoneNumbers($object) { $contact = $object->getContact(); if (!$contact) { return []; } return $this->rootProvider->getPhoneNumbers($contact); }
public function testGetEmail() { $opportunity = new Opportunity(); $contact = $this->getMockBuilder('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact')->disableOriginalConstructor()->getMock(); $this->assertNull($opportunity->getEmail()); $opportunity->setContact($contact); $contact->expects($this->once())->method('getEmail')->will($this->returnValue('*****@*****.**')); $this->assertEquals('*****@*****.**', $opportunity->getEmail()); }
public function testGetFirstName() { $salesFunnel = new SalesFunnel(); $opportunity = new Opportunity(); $opportunity->setName('test'); $salesFunnel->setOpportunity($opportunity); $this->assertEquals('test', $salesFunnel->getFirstName()); $salesFunnel = new SalesFunnel(); $lead = new Lead(); $lead->setName('test2'); $salesFunnel->setLead($lead); $this->assertEquals('test2', $salesFunnel->getFirstName()); }
/** * @param Contact $contact * @param B2bCustomer $customer * @param User $user * * @return Opportunity */ protected function createOpportunity($contact, $customer, $user) { $opportunity = new Opportunity(); $dataChannel = $this->getReference('default_channel'); $opportunity->setName($contact->getFirstName() . ' ' . $contact->getLastName()); $opportunity->setContact($contact); $opportunity->setOwner($user); $opportunity->setOrganization($this->organization); $opportunity->setCustomer($customer); $opportunity->setDataChannel($dataChannel); return $opportunity; }
protected function createOpportunity() { $opportunity = new Opportunity(); $opportunity->setName('opname'); $opportunity->setCustomer($this->getReference('default_b2bcustomer')); $opportunity->setDataChannel($this->getReference('default_channel')); $opportunity->setBudgetAmount(50.0); $opportunity->setProbability(10); $opportunity->setOrganization($this->organization); $this->em->persist($opportunity); $this->em->flush(); $this->setReference('default_opportunity', $opportunity); return $this; }
/** * @param string $key * @param Opportunity $entity */ public function fillEntityData($key, $entity) { $userRepo = $this->templateManager->getEntityRepository('Oro\\Bundle\\UserBundle\\Entity\\User'); $customerRepo = $this->templateManager->getEntityRepository('OroCRM\\Bundle\\SalesBundle\\Entity\\B2bCustomer'); $contactRepo = $this->templateManager->getEntityRepository('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact'); $leadRepo = $this->templateManager->getEntityRepository('OroCRM\\Bundle\\SalesBundle\\Entity\\Lead'); $channelRepo = $this->templateManager->getEntityRepository('OroCRM\\Bundle\\ChannelBundle\\Entity\\Channel'); switch ($key) { case 'Jerry Coleman': $entity->setName('Oro Inc. Opportunity Name'); $entity->setCustomer($customerRepo->getEntity('Jerry Coleman')); $entity->setDataChannel($channelRepo->getEntity('B2b channel|b2b')); $entity->setCreatedAt(new \DateTime()); $entity->setUpdatedAt(new \DateTime()); $entity->setOwner($userRepo->getEntity('John Doo')); $entity->setBudgetAmount(1000000); $entity->setContact($contactRepo->getEntity('Jerry Coleman')); $entity->setLead($leadRepo->getEntity('Jerry Coleman')); $entity->setStatus(new OpportunityStatus('In Progress')); return; } parent::fillEntityData($key, $entity); }
/** * @param array $result * @param array $opportunityHistory * @param Opportunity $opportunity * @param mixed $probability * * @return array */ protected function calculateOpportunityOldValue($result, $opportunityHistory, $opportunity, $probability) { ++$result['inProgressCount']; $oldBudgetAmount = $this->getHistoryOldValue($opportunityHistory, 'budgetAmount'); $budget = $oldBudgetAmount !== null ? $oldBudgetAmount : $opportunity->getBudgetAmount(); $result['budgetAmount'] += $budget; $result['weightedForecast'] += $budget * $probability; return $result; }
/** * Add opportunity * * @param Opportunity $opportunity * * @return Lead */ public function addOpportunity(Opportunity $opportunity) { $this->opportunities[] = $opportunity; $opportunity->setLead($this); return $this; }
/** * @param Opportunity $opportunity * @param array $changeSet * * @return bool|string */ protected function getOldStatus(Opportunity $opportunity, array $changeSet) { return isset($changeSet['status']) && $changeSet['status'][0] instanceof OpportunityStatus ? $changeSet['status'][0]->getName() : ($opportunity->getStatus() ? $opportunity->getStatus()->getName() : false); }
/** * Create opportunity form with data channel * * @Route("/create/{channelIds}", name="orocrm_sales_opportunity_data_channel_aware_create") * @Template("OroCRMSalesBundle:Opportunity:update.html.twig") * @AclAncestor("orocrm_sales_opportunity_create") * * @ParamConverter( * "channel", * class="OroCRMChannelBundle:Channel", * options={"id" = "channelIds"} * ) */ public function opportunityWithDataChannelCreateAction(Channel $channel) { $opportunity = new Opportunity(); $opportunity->setDataChannel($channel); return $this->update($opportunity); }
/** * @param Lead | Opportunity $entity * @param User $owner */ protected function loadSalesFlows($entity, $owner) { if ($entity instanceof Lead) { $step = 'start_from_lead'; $parameters = array('lead' => $entity); } else { $step = 'start_from_opportunity'; $parameters = array('opportunity' => $entity); } $parameters = array_merge(array('sales_funnel' => null, 'sales_funnel_owner' => $owner, 'sales_funnel_start_date' => new \DateTime('now')), $parameters); $salesFunnel = new SalesFunnel(); $salesFunnel->setDataChannel($this->getReference('default_channel')); if (!$this->workflowManager->isStartTransitionAvailable('b2b_flow_sales_funnel', $step, $salesFunnel, $parameters)) { return; } $salesFunnelItem = $this->workflowManager->startWorkflow('b2b_flow_sales_funnel', $salesFunnel, $step, $parameters); $salesFunnelItem->getData()->set('new_opportunity_name', $entity->getName())->set('new_company_name', $entity->getName()); if ($entity instanceof Lead) { if ($this->isTransitionAllowed($salesFunnelItem, 'qualify')) { $this->workflowManager->transit($salesFunnelItem, 'qualify'); } else { return; } } if (rand(1, 100) > 10) { $salesFunnelItem->getData()->set('budget_amount', mt_rand(10, 10000))->set('customer_need', mt_rand(10, 10000))->set('proposed_solution', mt_rand(10, 10000))->set('probability', $this->probabilities[array_rand($this->probabilities)]); if ($this->isTransitionAllowed($salesFunnelItem, 'develop')) { $this->workflowManager->transit($salesFunnelItem, 'develop'); if ($this->getRandomBoolean()) { $salesFunnelItem->getData()->set('close_revenue', mt_rand(10, 1000))->set('close_date', new \DateTime()); if ($this->getRandomBoolean()) { if ($this->isTransitionAllowed($salesFunnelItem, 'close_as_won')) { $this->workflowManager->transit($salesFunnelItem, 'close_as_won'); } } else { $salesFunnelItem->getData()->set('close_reason_name', 'cancelled')->set('close_date', new \DateTime('now', new \DateTimeZone('UTC'))); if ($this->isTransitionAllowed($salesFunnelItem, 'close_as_lost')) { $this->workflowManager->transit($salesFunnelItem, 'close_as_lost'); } } } } } }
/** * @depends testRemoveOpportunityFromB2bCustomer * * Test that no processing occured for b2bcustomers that were deleted * assert that onFlush event listeners not throwing exceptions */ public function testRemovedB2bCustomer() { $em = $this->getEntityManager(); $organization = $em->getRepository('OroOrganizationBundle:Organization')->getFirst(); $opportunity = new Opportunity(); $opportunity->setName('remove_b2bcustomer_test'); $opportunity->setDataChannel($this->getReference('default_channel')); $opportunity->setCloseRevenue(50); $opportunity->setBudgetAmount(50.0); $opportunity->setProbability(10); $opportunity->setStatus($em->getReference('OroCRMSalesBundle:OpportunityStatus', 'won')); $opportunity->setOrganization($organization); $opportunity->setCustomer($this->getReference('default_b2bcustomer')); /** @var B2bCustomer $b2bCustomer */ $b2bCustomer = $this->getReference('default_b2bcustomer'); $b2bCustomer->addOpportunity($opportunity); $em->persist($opportunity); $em->flush(); $em->remove($b2bCustomer); $em->flush(); }