示例#1
0
 /**
  * @param Request $request
  * @param Invoice $invoice
  *
  * @return Response
  */
 public function editAction(Request $request, Invoice $invoice)
 {
     if ($invoice->getStatus() === Graph::STATUS_PAID) {
         $this->flash($this->trans('invoice.edit.paid'), 'warning');
         return $this->redirectToRoute('_invoices_index');
     }
     $form = $this->createForm('invoice', $invoice);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $action = $request->request->get('save');
         $invoiceManager = $this->get('invoice.manager');
         /** @var PaymentRepository $paymentRepository */
         $paymentRepository = $this->getRepository('CSBillPaymentBundle:Payment');
         $totalPaid = $paymentRepository->getTotalPaidForInvoice($invoice);
         // @TODO: If current invoice total is updated to less than the total amount paid,
         // then the balance needs to be added as credit
         $invoice->setBalance($invoice->getTotal()->subtract($totalPaid));
         if ($action === Graph::STATUS_PENDING) {
             $invoiceManager->accept($invoice);
         } else {
             $this->save($invoice);
         }
         $this->flash($this->trans('invoice.edit.success'), 'success');
         return $this->redirect($this->generateUrl('_invoices_view', array('id' => $invoice->getId())));
     }
     return $this->render('CSBillInvoiceBundle:Default:edit.html.twig', array('form' => $form->createView(), 'invoice' => $invoice));
 }
示例#2
0
 /**
  * @param Quote|Invoice $object
  * @param Money         $total
  *
  * @return mixed
  */
 private function setDiscount($object, Money $total)
 {
     if (null !== $object->getDiscount()) {
         $discount = $total->multiply($object->getDiscount());
         $total = $total->subtract($discount);
         return $total;
     }
     return $total;
 }
示例#3
0
 /**
  * @param Invoice $invoice
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function sendAction(Invoice $invoice)
 {
     if ($invoice->getStatus() !== Graph::STATUS_PENDING) {
         $this->get('invoice.manager')->accept($invoice);
     } else {
         $this->get('billing.mailer')->sendInvoice($invoice);
     }
     $this->flash($this->trans('invoice.transition.action.sent'), 'success');
     return $this->redirect($this->generateUrl('_invoices_view', array('id' => $invoice->getId())));
 }
示例#4
0
 /**
  * @param Invoice $invoice
  */
 private function setItemsDescription(Invoice $invoice)
 {
     $now = Carbon::now();
     /** @var Item $item */
     foreach ($invoice->getItems() as $item) {
         $description = $item->getDescription();
         $description = str_replace(['{day}', '{day_name}', '{month}', '{year}'], [$now->day, $now->format('l'), $now->format('F'), $now->year], $description);
         $item->setDescription($description);
     }
     $this->entityManager->persist($invoice);
     $this->entityManager->flush();
 }
示例#5
0
 /**
  * @param Invoice $invoice
  *
  * @return Invoice
  */
 public function duplicate(Invoice $invoice)
 {
     // We don't use 'clone', since cloning an invoice will clone all the item id's and nested values.
     // We rather set it manually
     $newInvoice = new Invoice();
     $now = Carbon::now();
     $newInvoice->setCreated($now);
     $newInvoice->setClient($invoice->getClient());
     $newInvoice->setBaseTotal($invoice->getBaseTotal());
     $newInvoice->setDiscount($invoice->getDiscount());
     $newInvoice->setNotes($invoice->getNotes());
     $newInvoice->setTotal($invoice->getTotal());
     $newInvoice->setTerms($invoice->getTerms());
     $newInvoice->setUsers($invoice->getUsers()->toArray());
     $newInvoice->setBalance($newInvoice->getTotal());
     if (null !== $invoice->getTax()) {
         $newInvoice->setTax($invoice->getTax());
     }
     foreach ($invoice->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());
         }
         $newInvoice->addItem($invoiceItem);
     }
     $this->create($newInvoice);
     return $newInvoice;
 }
示例#6
0
文件: Client.php 项目: Codixis/CSBill
 /**
  * Add invoice.
  *
  * @param Invoice $invoice
  *
  * @return Client
  */
 public function addInvoice(Invoice $invoice)
 {
     $this->invoices[] = $invoice;
     $invoice->setClient($this);
     return $this;
 }
示例#7
0
文件: Mailer.php 项目: csbill/csbill
 /**
  * Emails an invoice to the customers.
  *
  * @param Invoice $invoice
  *
  * @return int If the email was successfully sent
  */
 public function sendInvoice(Invoice $invoice)
 {
     $htmlTemplate = $this->getTemplate('CSBillInvoiceBundle:Email:invoice.html.twig', ['invoice' => $invoice]);
     $textTemplate = $this->getTemplate('CSBillInvoiceBundle:Email:invoice.txt.twig', ['invoice' => $invoice]);
     $subject = $this->getSubject('invoice.email_subject', $invoice->getId());
     $users = [];
     foreach ($invoice->getUsers() as $user) {
         /* @var \CSBill\ClientBundle\Entity\Contact $user */
         $users[(string) $user->getEmail()] = $user->getFirstName() . ' ' . $user->getLastName();
     }
     $event = new InvoiceMailEvent();
     $event->setInvoice($invoice);
     $bcc = (string) $this->settings->get('invoice.bcc_address');
     $sent = $this->sendMessage($subject, $users, $htmlTemplate, $textTemplate, $event, $bcc);
     return $sent;
 }
示例#8
0
 /**
  * @ApiDoc(
  *     statusCodes={
  *         200="Returned when successful",
  *         400="Returned when the validation fails",
  *         403="Returned when the user is not authorized",
  *     },
  *     resource=true,
  *     description="Update an invoice",
  *     input="CSBill\InvoiceBundle\Form\Type\InvoiceType",
  *     output="CSBill\InvoiceBundle\Entity\Invoice",
  *     authentication=true,
  * )
  *
  * @param Request        $request
  * @param Entity\Invoice $invoice
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *
  * @throws \Exception
  *
  * @RestRoute\Put(path="/invoices/{invoiceId}")
  *
  * @ParamConverter("invoice", class="CSBillInvoiceBundle:Invoice", options={"id" : "invoiceId"})
  */
 public function updateInvoiceAction(Request $request, Entity\Invoice $invoice)
 {
     $originalStatus = $invoice->getStatus();
     $form = $this->get('form.factory')->create('invoice', $invoice);
     $form->handleRequest($request);
     if ($form->isValid()) {
         if ($invoice->getStatus() !== $originalStatus) {
             throw new \Exception('To change the status of an invoice, use the dedicated "status" method', 400);
         }
         $entityManager = $this->get('doctrine.orm.entity_manager');
         $entityManager->persist($invoice);
         $entityManager->flush();
         return $this->handleView($this->view($invoice));
     }
     if (!$form->isSubmitted()) {
         $form->submit([]);
     }
     return $this->handleView($this->view($form, Response::HTTP_BAD_REQUEST));
 }
示例#9
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());
 }
示例#10
0
 /**
  * @param Invoice $invoice
  *
  * @return array
  */
 public static function view(Invoice $invoice)
 {
     return ['invoice.menu.view', ['extras' => ['icon' => 'eye'], 'route' => '_invoices_view', 'routeParameters' => ['id' => $invoice->getId()]]];
 }
示例#11
0
文件: Mailer.php 项目: Codixis/CSBill
 /**
  * Emails an invoice to the customers.
  *
  * @param Invoice $invoice
  *
  * @return int If the email was successfully sent
  */
 public function sendInvoice(Invoice $invoice)
 {
     // TODO : this needs to come from settings or somewhere so it can be extended
     $htmlTemplate = $this->getTemplate('CSBillInvoiceBundle:Email:invoice.html.twig', array('invoice' => $invoice));
     $textTemplate = $this->getTemplate('CSBillInvoiceBundle:Email:invoice.txt.twig', array('invoice' => $invoice));
     $subject = $this->getSubject('invoice.email_subject', $invoice->getId());
     $users = array();
     foreach ($invoice->getUsers() as $user) {
         /* @var \CSBill\ClientBundle\Entity\Contact $user */
         $users[(string) $user->getPrimaryDetail('email')] = $user->getFirstname() . ' ' . $user->getLastname();
     }
     $event = new InvoiceMailEvent();
     $event->setInvoice($invoice);
     $bcc = (string) $this->settings->get('invoice.bcc_address');
     $sent = $this->sendMessage($subject, $users, $htmlTemplate, $textTemplate, $event, $bcc);
     return $sent;
 }