static function onPaymentAfterInsert(Am_Event_PaymentAfterInsert $event)
 {
     /**
      * This e-mail is sent for first payment in invoice only
      * another template must be used for the following payments
      */
     if ($event->getInvoice()->getPaymentsCount() != 1) {
         return;
     }
     if ($event->getDi()->config->get('send_payment_mail')) {
         $et = Am_Mail_Template::load('send_payment_mail', $event->getUser()->lang);
         if ($et) {
             $et->setUser($event->getUser())->setInvoice($event->getInvoice())->setPayment($event->getPayment())->setInvoice_text($event->getInvoice()->render());
             if (Am_Di::getInstance()->config->get('send_pdf_invoice', false)) {
                 try {
                     $invoice = new Am_Pdf_Invoice($event->getInvoice());
                     $et->getMail()->createAttachment($invoice->render(), 'application/pdf', Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $invoice->getFileName());
                 } catch (Exception $e) {
                     $this->getDi()->errorLogTable->logException($e);
                 }
             }
             $et->send($event->getUser());
         }
     }
     if ($event->getDi()->config->get('send_payment_admin')) {
         $et = Am_Mail_Template::load('send_payment_admin', $event->getUser()->lang);
         if ($et) {
             $et->setUser($event->getUser())->setInvoice($event->getInvoice())->setPayment($event->getPayment())->setInvoice_text($event->getInvoice()->render());
             $et->send(Am_Mail_Template::TO_ADMIN);
         }
     }
 }
 function getInvoiceAction()
 {
     $id = $this->getFiltered('id');
     if (!$id) {
         throw new Am_Exception_InputError("Wrong invoice# passed");
     }
     $invoice = $this->getDi()->invoiceTable->findFirstByPublicId($id);
     if (!$invoice) {
         throw new Am_Exception(___("Invoice not found"));
     }
     if ($invoice->user_id != $this->user->user_id) {
         throw new Am_Exception_Security("Foreign invoice requested : [{$id}] for {$this->user->user_id}");
     }
     $pdfInvoice = new Am_Pdf_Invoice($invoice);
     $pdfInvoice->setDi($this->getDi());
     $pdfInvoiceRendered = $pdfInvoice->render();
     $this->noCache();
     header("Content-type: application/pdf");
     header("Content-Length: " . strlen($pdfInvoiceRendered));
     header("Content-Disposition: attachment; filename={$pdfInvoice->getFileName()}");
     echo $pdfInvoiceRendered;
 }