protected function _addPendingInvoiceAndSend(Invoice $invoice, Am_Form $form, $vars) { if ($vars['paysys_id']) { try { $invoice->setPaysystem($vars['paysys_id'], false); } catch (Am_Exception_InputError $e) { $form->setError($e->getMessage()); return false; } } $errors = $invoice->validate(); if ($errors) { $form->setError(current($errors)); return false; } $invoice->data()->set('added-by-admin', $this->getDi()->authAdmin->getUserId()); $invoice->due_date = $vars['tm_due']; $invoice->save(); $et = Am_Mail_Template::load('invoice_pay_link', $invoice->getUser()->lang ? $invoice->getUser()->lang : null); $et->setUser($invoice->getUser()); $et->setUrl(ROOT_SURL . sprintf('/pay/%s', $invoice->getSecureId('payment-link'))); $et->setMessage($vars['message']); $et->setInvoice($invoice); $et->setInvoice_text($invoice->render()); $et->send($invoice->getUser()); return true; }