/** * 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; }
/** * 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; }