/**
  * @param AccountUser|null $accountUser
  * @return PriceList
  */
 public function getPriceList(AccountUser $accountUser = null)
 {
     if ($accountUser) {
         $account = $accountUser->getAccount();
         if ($account) {
             $priceList = $this->getPriceListRepository()->getPriceListByAccount($account);
             if ($priceList) {
                 return $priceList;
             }
             $priceList = $this->getPriceListFromAccountTree($account);
             if ($priceList) {
                 return $priceList;
             }
             $priceList = $this->getPriceListFromAccountGroup($account);
             if ($priceList) {
                 return $priceList;
             }
             $priceList = $this->getPriceListFromAccountGroupTree($account);
             if ($priceList) {
                 return $priceList;
             }
         }
     }
     $priceList = $this->getPriceListFromWebsite();
     if ($priceList) {
         return $priceList;
     }
     return $this->getPriceListRepository()->getDefault();
 }
 /**
  * @param AccountUser $accountUser
  * @return QueryBuilder
  */
 public function getAvailableRolesByAccountUserQueryBuilder(AccountUser $accountUser)
 {
     $qb = $this->createQueryBuilder('accountUserRole');
     $qb->where($qb->expr()->andX($qb->expr()->orX($qb->expr()->isNull('accountUserRole.account'), $qb->expr()->eq('accountUserRole.account', ':account')), $qb->expr()->eq('accountUserRole.organization', ':organization')));
     $qb->setParameter('account', $accountUser->getAccount());
     $qb->setParameter('organization', $accountUser->getOrganization());
     return $qb;
 }
 /**
  * @param AccountUserRole|AbstractRole $role
  * @param EntityManager                $manager
  */
 protected function removeOriginalRoleFromUsers(AccountUserRole $role, EntityManager $manager)
 {
     if (!$role->getId() || $role->getId() === $this->newRole->getId()) {
         return;
     }
     array_map(function (AccountUser $accountUser) use($role, $manager) {
         if ($accountUser->getAccount()->getId() === $this->loggedAccountUser->getAccount()->getId()) {
             $accountUser->removeRole($role);
             $manager->persist($accountUser);
         }
     }, $this->appendUsers);
 }
 /**
  * "Success" form handler
  *
  * @param ShoppingList $entity
  * @return bool
  */
 protected function onSuccess(ShoppingList $entity)
 {
     $rfpRequest = new RFPRequest();
     $rfpRequest->setFirstName($this->user->getFirstName())->setLastName($this->user->getLastName())->setEmail($this->user->getEmail())->setPhone('')->setRole('')->setBody('')->setCompany($this->user->getOrganization() ? $this->user->getOrganization()->getName() : '')->setAccountUser($this->user)->setAccount($this->user->getAccount())->setStatus($this->requestStatus);
     foreach ($entity->getLineItems() as $shoppingListLineItem) {
         $requestProduct = new RequestProduct();
         $requestProduct->setProduct($shoppingListLineItem->getProduct());
         $requestProductItem = new RequestProductItem();
         $requestProductItem->setQuantity($shoppingListLineItem->getQuantity())->setProductUnit($shoppingListLineItem->getUnit());
         $requestProduct->addRequestProductItem($requestProductItem);
         $rfpRequest->addRequestProduct($requestProduct);
     }
     try {
         $this->manager->persist($rfpRequest);
         $this->manager->flush();
         $this->rfpRequest = $rfpRequest;
     } catch (DBALException $e) {
         $this->exception = $e;
         return false;
     }
     return true;
 }
 /**
  * @param Quote $quote
  * @param AccountUser|null $user
  * @param array|null $selectedOffers
  * @return Order
  */
 public function convert(Quote $quote, AccountUser $user = null, array $selectedOffers = null)
 {
     $accountUser = $user ?: $quote->getAccountUser();
     $account = $user ? $user->getAccount() : $quote->getAccount();
     $order = new Order();
     $order->setAccount($account)->setAccountUser($accountUser)->setOwner($quote->getOwner())->setOrganization($quote->getOrganization());
     if (!$selectedOffers) {
         foreach ($quote->getQuoteProducts() as $quoteProduct) {
             /** @var QuoteProductOffer $productOffer */
             $productOffer = $quoteProduct->getQuoteProductOffers()->first();
             $order->addLineItem($this->createOrderLineItem($productOffer));
         }
     } else {
         foreach ($selectedOffers as $selectedOffer) {
             /** @var QuoteProductOffer $offer */
             $offer = $selectedOffer[self::FIELD_OFFER];
             $order->addLineItem($this->createOrderLineItem($offer, (double) $selectedOffer[self::FIELD_QUANTITY]));
         }
     }
     $this->orderCurrencyHandler->setOrderCurrency($order);
     $this->fillSubtotals($order);
     return $order;
 }
 /**
  *
  * @param AccountUser $accountUser
  * @return JsonResponse
  */
 public function getAccountIdAction(AccountUser $accountUser)
 {
     return new JsonResponse(['accountId' => $accountUser->getAccount() ? $accountUser->getAccount()->getId() : null]);
 }
 /**
  * @param AccountUser $accountUser
  * @return null|Account
  */
 protected function getAccount(AccountUser $accountUser = null)
 {
     $account = $this->getOrderHandler()->getAccount();
     if (!$account && $accountUser) {
         $account = $accountUser->getAccount();
     }
     if ($account && $accountUser) {
         $this->validateRelation($accountUser, $account);
     }
     return $account;
 }
Esempio n. 8
0
 /**
  * @param AccountUser $user
  * @param AccountOwnerAwareInterface $object
  * @return bool
  */
 protected function isSameAccount(AccountUser $user, AccountOwnerAwareInterface $object)
 {
     return $user->getAccount()->getId() === $object->getAccount()->getId();
 }
Esempio n. 9
0
 /**
  * @param AccountUser $accountUser
  *
  * @return Order
  */
 public function setAccountUser(AccountUser $accountUser = null)
 {
     $this->accountUser = $accountUser;
     if ($accountUser && $accountUser->getAccount() && !$this->getAccount()) {
         $this->setAccount($accountUser->getAccount());
     }
     return $this;
 }