public function run() { $this->grid->getDi()->plugins_payment->loadEnabled()->getAllEnabled(); $ds = $this->grid->getDataSource(); $fn = tempnam(DATA_DIR, 'zip_'); $zip = new ZipArchive(); $zip->open($fn, ZipArchive::OVERWRITE); $st = $ds->query(); while ($iprec = $this->grid->getDi()->db->fetchRow($st)) { $ip = $ds->getDataSourceQuery()->getTable()->createRecord($iprec); $pdf = Am_Pdf_Invoice::create($ip); $zip->addFromString($pdf->getFileName(), $pdf->render()); } $zip->close(); register_shutdown_function(array($this, 'cleanup'), $fn); $helper = new Am_Controller_Action_Helper_SendFile(); $helper->sendFile($fn, 'application/octet-stream', array('filename' => sprintf('invoices-%s.zip', sqlDate('now')))); }
static function onPaymentWithAccessAfterInsert(Am_Event_PaymentWithAccessAfterInsert $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; $event->getDi()->plugins_payment->loadEnabled()->getAllEnabled(); if ($event->getDi()->config->get('send_payment_mail')) { $et = Am_Mail_Template::load('send_payment_mail', $event->getUser()->lang); if ($et && $event->getPayment()->amount > 0) { $et->setUser($event->getUser())->setInvoice($event->getInvoice())->setPayment($event->getPayment())->setInvoice_text($event->getInvoice()->render('', $event->getPayment())); if (Am_Di::getInstance()->config->get('send_pdf_invoice', false)) { try { $invoice = Am_Pdf_Invoice::create($event->getPayment()); $invoice->setDi(Am_Di::getInstance()); $et->getMail()->createAttachment($invoice->render(), 'application/pdf', Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $invoice->getFileName()); } catch (Exception $e) { Am_Di::getInstance()->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 && $event->getPayment()->amount > 0) { $et->setUser($event->getUser())->setInvoice($event->getInvoice())->setPayment($event->getPayment())->setInvoice_text($event->getInvoice()->render('', $event->getPayment())); if (Am_Di::getInstance()->config->get('send_pdf_invoice', false)) { try { $invoice = Am_Pdf_Invoice::create($event->getPayment()); $invoice->setDi(Am_Di::getInstance()); $et->getMail()->createAttachment($invoice->render(), 'application/pdf', Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $invoice->getFileName()); } catch (Exception $e) { Am_Di::getInstance()->errorLogTable->logException($e); } } $et->send(Am_Mail_Template::TO_ADMIN); } } }
function invoiceAction() { $this->getDi()->authAdmin->getUser()->checkPermission('grid_invoice', 'browse'); if ($payment_id = $this->_request->getInt('payment_id')) { $payment = $this->getDi()->invoicePaymentTable->load($this->_request->getInt('payment_id')); } else { if ($refund_id = $this->_request->getInt('refund_id')) { $payment = $this->getDi()->invoiceRefundTable->load($this->_request->getInt('refund_id')); } } $this->getDi()->plugins_payment->loadEnabled()->getAllEnabled(); $pdfInvoice = Am_Pdf_Invoice::create($payment); $pdfInvoice->setDi($this->getDi()); $this->_helper->sendFile->sendData($pdfInvoice->render(), 'application/pdf', $pdfInvoice->getFileName()); }
function getInvoiceAction() { $id = $this->getDi()->app->reveal($this->getParam('id')); if (!$id) { throw new Am_Exception_InputError("Wrong invoice# passed"); } $payment = $this->getDi()->invoicePaymentTable->load($id); if (!$payment) { throw new Am_Exception(___("Invoice not found")); } if ($payment->user_id != $this->user->user_id) { throw new Am_Exception_Security("Foreign invoice requested : [{$id}] for {$this->user->user_id}"); } $this->getDi()->plugins_payment->loadEnabled()->getAllEnabled(); $pdfInvoice = Am_Pdf_Invoice::create($payment); $pdfInvoice->setDi($this->getDi()); $this->_helper->sendFile->sendData($pdfInvoice->render(), 'application/pdf', $pdfInvoice->getFileName()); }