/**
  * Create a new payment
  *
  * @param void
  * @return null
  */
 function add()
 {
     if ($this->active_invoice->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $max_payment = $this->active_invoice->getMaxPayment();
     $invoice_payment_data = $this->request->post('invoice_payment');
     if (!is_array($invoice_payment_data)) {
         $invoice_payment_data = array('amount' => $max_payment, 'paid_on' => new DateValue());
     }
     // if
     js_assign('max_invoice_payment', $max_payment);
     $this->smarty->assign('invoice_payment_data', $invoice_payment_data);
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $this->active_invoice_payment->setAttributes($invoice_payment_data);
         $this->active_invoice_payment->setInvoiceId($this->active_invoice->getId());
         $this->active_invoice_payment->setCreatedBy($this->logged_user);
         $this->active_invoice_payment->setCreatedOn(new DateTimeValue());
         $this->active_invoice_payment->setSendNotifications((bool) $this->request->post('notify_company'));
         $save = $this->active_invoice_payment->save();
         if ($save && !is_error($save)) {
             db_commit();
             flash_success('Payment #:id has been added', array('id' => $this->active_invoice_payment->getId()));
             $this->redirectToUrl($this->active_invoice->getViewUrl());
         } else {
             db_rollback();
             $this->smarty->assign('errors', $save);
         }
         // if
     }
     // if
 }