Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getMassActions()
 {
     $archiveAction = new MassAction('Archive', function ($ids) {
         /** @var QuoteRepository $quoteRepository */
         $quoteRepository = $this->entityManager->getRepository('CSBillQuoteBundle:Quote');
         /** @var Quote[] $quotes */
         $quotes = $quoteRepository->findBy(array('id' => $ids));
         /** @var FlashBag $flashBag */
         $flashBag = $this->session->getBag('flashes');
         $failed = 0;
         foreach ($quotes as $quote) {
             $finite = $this->finite->get($quote, Graph::GRAPH);
             if ($finite->can(Graph::TRANSITION_ARCHIVE)) {
                 $quote->archive();
                 $this->entityManager->persist($quote);
             } else {
                 $flashBag->add('warning', 'quote.transition.exception.archive');
                 ++$failed;
             }
         }
         if ($failed !== count($quotes)) {
             $this->entityManager->flush();
             $flashBag->add('success', 'quote.archive.success');
         }
     }, true);
     $archiveAction->setIcon('archive');
     $archiveAction->setClass('warning');
     return array($archiveAction, new DeleteMassAction());
 }
Ejemplo n.º 2
0
 /**
  * @param Quote  $quote
  * @param string $transition
  *
  * @return bool
  *
  * @throws InvalidTransitionException
  */
 private function applyTransition(Quote $quote, $transition)
 {
     $stateMachine = $this->stateMachine->get($quote, Graph::GRAPH);
     if ($stateMachine->can($transition)) {
         $oldStatus = $quote->getStatus();
         $stateMachine->apply($transition);
         $this->entityManager->persist($quote);
         $this->entityManager->flush();
         $newStatus = $quote->getStatus();
         $parameters = array('quote' => $quote, 'old_status' => $oldStatus, 'new_status' => $newStatus, 'transition' => $transition);
         $notification = new QuoteStatusNotification($parameters);
         $this->notification->sendNotification('quote_status_update', $notification);
         return true;
     }
     throw new InvalidTransitionException($transition);
 }
Ejemplo n.º 3
0
 /**
  * @param Invoice $invoice
  * @param string  $transition
  *
  * @return bool
  *
  * @throws InvalidTransitionException
  */
 private function applyTransition(Invoice $invoice, $transition)
 {
     $stateMachine = $this->stateMachine->get($invoice, Graph::GRAPH);
     if ($stateMachine->can($transition)) {
         $oldStatus = $invoice->getStatus();
         $stateMachine->apply($transition);
         $newStatus = $invoice->getStatus();
         $parameters = ['invoice' => $invoice, 'old_status' => $oldStatus, 'new_status' => $newStatus, 'transition' => $transition];
         // Do not send status updates for new invoices
         if ($transition !== Graph::TRANSITION_NEW) {
             $notification = new InvoiceStatusNotification($parameters);
             $this->notification->sendNotification('invoice_status_update', $notification);
         }
         return true;
     }
     throw new InvalidTransitionException($transition);
 }
Ejemplo n.º 4
0
 /**
  * @param Quote $quote
  *
  * @return Quote
  */
 public function duplicate(Quote $quote)
 {
     // We don't use 'clone', since cloning aq quote will clone all the item id's and nested values.
     // We rather set it manually
     $newQuote = new Quote();
     $now = Carbon::now();
     $newQuote->setCreated($now);
     $newQuote->setClient($quote->getClient());
     $newQuote->setBaseTotal($quote->getBaseTotal());
     $newQuote->setDiscount($quote->getDiscount());
     $newQuote->setNotes($quote->getNotes());
     $newQuote->setTotal($quote->getTotal());
     $newQuote->setTerms($quote->getTerms());
     $newQuote->setUsers($quote->getUsers()->toArray());
     if (null !== $quote->getTax()) {
         $newQuote->setTax($quote->getTax());
     }
     foreach ($quote->getItems() as $item) {
         $invoiceItem = new Item();
         $invoiceItem->setCreated($now);
         $invoiceItem->setTotal($item->getTotal());
         $invoiceItem->setDescription($item->getDescription());
         $invoiceItem->setPrice($item->getPrice());
         $invoiceItem->setQty($item->getQty());
         if (null !== $item->getTax()) {
             $invoiceItem->setTax($item->getTax());
         }
         $newQuote->addItem($invoiceItem);
     }
     $this->dispatcher->dispatch(QuoteEvents::QUOTE_PRE_CREATE, new QuoteEvent($newQuote));
     $stateMachine = $this->stateMachine->get($newQuote, Graph::GRAPH);
     if ($stateMachine->can(Graph::TRANSITION_NEW)) {
         $stateMachine->apply(Graph::TRANSITION_NEW);
     }
     $this->entityManager->persist($newQuote);
     $this->entityManager->flush();
     $this->dispatcher->dispatch(QuoteEvents::QUOTE_POST_CREATE, new QuoteEvent($newQuote));
     return $newQuote;
 }