Example #1
0
 /**
  * @param Quote $quote
  *
  * @return Invoice
  *
  * @throws InvalidTransitionException
  */
 public function accept(Quote $quote)
 {
     $this->dispatcher->dispatch(QuoteEvents::QUOTE_PRE_ACCEPT, new QuoteEvent($quote));
     $invoice = $this->invoiceManager->createFromQuote($quote);
     $this->applyTransition($quote, Graph::TRANSITION_ACCEPT);
     $this->dispatcher->dispatch(QuoteEvents::QUOTE_POST_ACCEPT, new QuoteEvent($quote));
     return $invoice;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getMassActions()
 {
     $archiveAction = new MassAction('Archive', function ($ids) {
         /** @var InvoiceRepository $invoiceRepository */
         $invoiceRepository = $this->entityManager->getRepository('CSBillInvoiceBundle:Invoice');
         /** @var Invoice[] $invoices */
         $invoices = $invoiceRepository->findBy(array('id' => $ids));
         /** @var FlashBag $flashBag */
         $flashBag = $this->session->getBag('flashes');
         $failed = 0;
         foreach ($invoices as $invoice) {
             try {
                 $this->invoiceManager->archive($invoice);
             } catch (InvalidTransitionException $e) {
                 $flashBag->add('warning', $e->getMessage());
                 ++$failed;
             }
         }
         if ($failed !== count($invoices)) {
             $flashBag->add('success', 'invoice.archive.success');
         }
     }, true);
     $archiveAction->setIcon('archive');
     $archiveAction->setClass('warning');
     return array($archiveAction, new DeleteMassAction());
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function process()
 {
     /** @var InvoiceRepository $invoiceRepository */
     $invoiceRepository = $this->entityManager->getRepository('CSBillInvoiceBundle:Invoice');
     $invoices = $invoiceRepository->getRecurringInvoices();
     foreach ($invoices as $invoice) {
         $recurringInfo = $invoice->getRecurringInfo();
         if (null !== $recurringInfo->getDateEnd() && Carbon::instance($recurringInfo->getDateEnd())->isFuture()) {
             continue;
         }
         $cron = CronExpression::factory($recurringInfo->getFrequency());
         if (true === $cron->isDue(Carbon::now())) {
             $newInvoice = $this->invoiceManager->duplicate($invoice);
             $this->setItemsDescription($newInvoice);
             $this->invoiceManager->accept($newInvoice);
         }
     }
 }
Example #4
0
 public function testMarkPaid()
 {
     $invoice = new Invoice();
     $this->dispatcher->shouldReceive('dispatch')->once()->withAnyArgs();
     $this->dispatcher->shouldReceive('dispatch')->once()->withAnyArgs();
     // Ensure paid date is empty when creating invoice
     $this->assertNull($invoice->getPaidDate());
     $this->manager->pay($invoice);
     $this->assertInstanceOf('DateTime', $invoice->getPaidDate());
     $this->assertSame(null, $invoice->getStatus());
 }
 /**
  * @param PaymentCompleteEvent $event
  */
 public function onPaymentComplete(PaymentCompleteEvent $event)
 {
     $payment = $event->getPayment();
     $status = (string) $payment->getStatus();
     $this->addFlashMessage($status, $payment->getMessage());
     if ('credit' === $payment->getMethod()->getPaymentMethod()) {
         $creditRepository = $this->manager->getRepository('CSBillClientBundle:Credit');
         $creditRepository->deductCredit($payment->getClient(), new Money($payment->getTotalAmount(), $this->currency));
     }
     if (null !== ($invoice = $event->getPayment()->getInvoice())) {
         if ($status === Status::STATUS_CAPTURED && $this->invoiceManager->isFullyPaid($invoice)) {
             $this->invoiceManager->pay($invoice);
         } else {
             $paymentRepository = $this->manager->getRepository('CSBillPaymentBundle:Payment');
             $totalPaid = $paymentRepository->getTotalPaidForInvoice($invoice);
             $invoice->setBalance($invoice->getTotal()->subtract($totalPaid));
             $this->manager->persist($invoice);
             $this->manager->flush();
         }
         $event->setResponse(new RedirectResponse($this->router->generate('_view_invoice_external', array('uuid' => $invoice->getUuid()))));
     }
 }