예제 #1
0
 protected function createSalesFunnelByOpportunity()
 {
     $date = new \DateTime('now');
     $salesFunnel = new SalesFunnel();
     $salesFunnel->setDataChannel($this->getReference('default_channel'));
     $salesFunnel->setOpportunity($this->getReference('default_opportunity'));
     $salesFunnel->setOwner($this->getUser());
     $salesFunnel->setStartDate($date);
     $salesFunnel->setOrganization($this->organization);
     $this->em->persist($salesFunnel);
     $this->em->flush();
 }
예제 #2
0
 /**
  * @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');
                     }
                 }
             }
         }
     }
 }