You are here

function commerce_invoice_form_submit in Commerce Invoice 7.2

Form API submit callback for the invoice form.

File

./commerce_invoice.admin.inc, line 257
Administrative form and page callbacks for the Commerce Invoice module.

Code

function commerce_invoice_form_submit(&$form, &$form_state) {
  if (!empty($form_state['values']['invoice_date']) && !is_numeric($form_state['values']['invoice_date'])) {
    $invoice_date = strtotime($form_state['values']['invoice_date']);
  }
  if (!empty($form_state['values']['invoice_due']) && !is_numeric($form_state['values']['invoice_due'])) {
    $invoice_due = strtotime($form_state['values']['invoice_due']);
  }

  /** @var \Drupal\commerce_invoice\Entity\Invoice $invoice */
  $invoice = entity_ui_form_submit_build_entity($form, $form_state);
  if (!empty($invoice_date)) {
    $invoice->invoice_date = $invoice_date;
  }
  if (!empty($invoice_due)) {
    $invoice->invoice_due = $invoice_due;
  }
  commerce_invoice_calculate_total($invoice);
  $invoice
    ->save();
  $form_state['redirect'] = 'admin/commerce/invoices';
}