Beispiel #1
0
 /**
  * @return array
  */
 public function testCreateB2bCustomer()
 {
     $request = ['b2bcustomer' => ['name' => 'b2bcustomer_name_' . mt_rand(1, 500), 'account' => $this->getReference('default_account')->getId(), 'owner' => '1', 'dataChannel' => self::$dataChannel->getId(), 'shippingAddress' => $this->testAddress]];
     $this->client->request('POST', $this->getUrl('oro_api_post_b2bcustomer'), $request);
     $result = $this->getJsonResponseContent($this->client->getResponse(), 201);
     $request['id'] = $result['id'];
     return $request;
 }
Beispiel #2
0
 /**
  * @return array
  */
 public function testPostLead()
 {
     $request = ["lead" => ['name' => 'lead_name_' . mt_rand(1, 500), 'firstName' => 'first_name_' . mt_rand(1, 500), 'lastName' => 'last_name_' . mt_rand(1, 500), 'owner' => '1', 'dataChannel' => self::$dataChannel->getId()]];
     $this->client->request('POST', $this->getUrl('oro_api_post_lead'), $request);
     $result = $this->getJsonResponseContent($this->client->getResponse(), 201);
     $request['id'] = $result['id'];
     return $request;
 }
 public function testCreate()
 {
     $crawler = $this->client->request('GET', $this->getUrl('orocrm_sales_b2bcustomer_create'));
     $form = $crawler->selectButton('Save and Close')->form();
     $name = 'name' . $this->generateRandomString();
     $form['orocrm_sales_b2bcustomer_form[name]'] = $name;
     $form['orocrm_sales_b2bcustomer_form[account]'] = self::$account->getId();
     $form['orocrm_sales_b2bcustomer_form[dataChannel]'] = self::$channel->getId();
     $form['orocrm_sales_b2bcustomer_form[owner]'] = 1;
     $this->client->followRedirects(true);
     $crawler = $this->client->submit($form);
     $result = $this->client->getResponse();
     $this->assertHtmlResponseStatusCodeEquals($result, 200);
     $this->assertContains("Customer saved", $crawler->html());
 }
 /**
  * @param Channel $channel
  */
 public function scheduleRecalculation(Channel $channel = null)
 {
     if ($channel) {
         $argument = sprintf('--channel=%s', $channel->getId());
         if ($this->isJobRunning($argument)) {
             return;
         }
         $isActiveChannel = $channel->getStatus() === Channel::STATUS_ACTIVE;
         $channelData = $channel->getData();
         $rfmEnabled = !empty($channelData[RFMAwareInterface::RFM_STATE_KEY]);
         if (!$isActiveChannel || !$rfmEnabled) {
             return;
         }
     }
     if ($this->getJob()) {
         return;
     }
     $args = [];
     if ($channel) {
         $argument = sprintf('--channel=%s', $channel->getId());
         $channelJob = $this->getJob($argument);
         if ($channelJob) {
             return;
         }
         $args = [$argument];
     }
     $job = new Job(CalculateAnalyticsCommand::COMMAND_NAME, $args);
     $em = $this->doctrineHelper->getEntityManager($job);
     if (!$channel) {
         $channelJobs = $this->getJob('--channel');
         if ($channelJobs) {
             foreach ($channelJobs as $channelJob) {
                 $em->remove($channelJob);
             }
         }
     }
     $em->persist($job);
     $em->flush($job);
 }
 /**
  * @param int[]   $accountIds
  * @param Channel $channel
  * @param string  $customerIdentity
  * @param string  $lifetimeFieldName
  */
 private function updateLifetime(array $accountIds, Channel $channel, $customerIdentity, $lifetimeFieldName)
 {
     $customerMetadata = $this->em->getClassMetadata($customerIdentity);
     $lifetimeColumnName = $customerMetadata->getColumnName($lifetimeFieldName);
     $this->em->getConnection()->executeUpdate('UPDATE orocrm_channel_lifetime_hist SET status = :status
          WHERE data_channel_id = :channel_id AND account_id IN (:account_ids)', ['status' => false, 'channel_id' => $channel->getId(), 'account_ids' => $accountIds], ['status' => Type::BOOLEAN, 'channel_id' => Type::INTEGER, 'account_ids' => Connection::PARAM_INT_ARRAY]);
     $this->em->getConnection()->executeUpdate('INSERT INTO orocrm_channel_lifetime_hist' . ' (account_id, data_channel_id, status, amount, created_at)' . sprintf(' SELECT e.account_id AS hist_account_id, e.data_channel_id AS hist_data_channel_id,' . ' e.account_id > 0 as hist_status, SUM(COALESCE(e.%s, 0)) AS hist_amount,' . ' TIMESTAMP :created_at AS hist_created_at', $lifetimeColumnName) . sprintf(' FROM %s AS e', $customerMetadata->getTableName()) . ' WHERE e.data_channel_id = :channel_id AND e.account_id IN (:account_ids)' . ' GROUP BY hist_account_id, hist_data_channel_id, hist_status, hist_created_at', ['created_at' => new \DateTime(null, new \DateTimeZone('UTC')), 'channel_id' => $channel->getId(), 'account_ids' => $accountIds], ['created_at' => Type::DATETIME, 'channel_id' => Type::INTEGER, 'account_ids' => Connection::PARAM_INT_ARRAY]);
 }
Beispiel #6
0
 /**
  * @Route(
  *      "/status/change/{id}",
  *      requirements={"id"="\d+"},
  *      name="orocrm_channel_change_status"
  *  )
  * @AclAncestor("orocrm_channel_update")
  */
 public function changeStatusAction(Channel $channel)
 {
     if ($channel->getStatus() == Channel::STATUS_ACTIVE) {
         $message = 'orocrm.channel.controller.message.status.deactivated';
         $channel->setStatus(Channel::STATUS_INACTIVE);
     } else {
         $message = 'orocrm.channel.controller.message.status.activated';
         $channel->setStatus(Channel::STATUS_ACTIVE);
     }
     $this->getDoctrine()->getManager()->flush();
     $event = new ChannelChangeStatusEvent($channel);
     $this->get('event_dispatcher')->dispatch(ChannelChangeStatusEvent::EVENT_NAME, $event);
     $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans($message));
     return $this->redirect($this->generateUrl('orocrm_channel_view', ['id' => $channel->getId(), '_enableContentProviders' => 'mainMenu']));
 }
    /**
     * @param Channel   $channel
     * @param \DateTime $date Datetime object in system timezone
     *
     * @return float
     */
    private function getAggregatedValue(Channel $channel, \DateTime $date)
    {
        $sql = <<<SQL
  SELECT AVG(h.{amount})
  FROM {tableName} h
  JOIN(
    SELECT MAX(h1.{id}) as identity
    FROM {tableName} h1
    WHERE h1.{dataChannel} = :channelId AND h1.{createdAt} <= :endDate
    GROUP BY h1.{account}
  ) maxres ON maxres.identity = h.{id}
SQL;
        $sqlNames = $this->getSQLColumnNamesArray();
        $sql = preg_replace_callback('/{(\\w+)}/', function ($matches) use($sqlNames) {
            $fieldName = trim(end($matches));
            if (isset($sqlNames[$fieldName])) {
                return $sqlNames[$fieldName];
            }
            throw new \RuntimeException(sprintf('Entity does not have field named "%s"', $fieldName));
        }, $sql);
        $calculationPeriodEnd = Carbon::instance($date);
        $calculationPeriodEnd->firstOfMonth();
        $calculationPeriodEnd->addMonth();
        return $this->getEntityManager()->getConnection()->executeQuery($sql, ['channelId' => $channel->getId(), 'endDate' => $calculationPeriodEnd], ['channelId' => Type::INTEGER, 'endDate' => Type::DATETIME])->fetchColumn(0);
    }