Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }