You are here

function _invoice_get_invoice_items in Invoice 6

Same name and namespace in other branches
  1. 7 invoice_form.inc \_invoice_get_invoice_items()

Form helper function to get all invoice items

Parameters

string $type:

integer $invoice_id:

Return value

array

1 call to _invoice_get_invoice_items()
invoice_form in ./invoice_form.inc
Implementatin of node_form()

File

./invoice_form.inc, line 715
Invoice module

Code

function _invoice_get_invoice_items($invoice_id = 0, $type = NULL) {
  $i = 0;
  $invoice_id = intval($invoice_id);
  $invoice_items_table_rows = array();
  $sql_addition = $invoice_id > 0 ? ' ' . intval($invoice_id) : '';
  $result = db_query("SELECT * FROM {invoice_items} WHERE uid=%d AND invoice_id=%d ORDER BY created ASC", $GLOBALS['user']->uid, $invoice_id);

  // implement hook_form() here
  $form['page_names'] = array();
  $form['page_weights'] = array();
  $weight_column = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#default_value' => 20,
    '#delta' => 10,
    '#access' => TRUE,
    '#description' => t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'),
  );
  $weight_column = process_weight($weight_column);
  while ($row = db_fetch_object($result)) {
    $i++;
    $token = drupal_get_token($row->iid);
    $invoice_items_table_rows[] = array(
      'data' => array(
        nl2br(check_plain($row->description)),
        $row->vat . '%',
        $row->quantity,
        _invoice_round_and_format_money($row->unitcost, 3),
        _invoice_round_and_format_money($row->unitcost * _invoice_vat_percent_to_decimal($row->vat), 2),
        _invoice_round_and_format_money($row->quantity * $row->unitcost, 2),
        _invoice_round_and_format_money($row->quantity * $row->unitcost * _invoice_vat_percent_to_decimal($row->vat), 2),
        array(
          'data' => _invoice_get_icon('edit', NULL, array(
            'class' => 'action-button edit-action mouse-pointer',
            'title' => t('Edit'),
          )) . _invoice_get_icon('delete', NULL, array(
            'class' => 'action-button delete-action mouse-pointer',
            'title' => t('Delete'),
          )),
          'class' => 'actions',
        ),
      ),
      'class' => $type . 'item-' . $row->iid,
      ' iitoken-' . $token,
      ' invoice-item draggable',
    );
  }
  return array(
    'rows' => $invoice_items_table_rows,
    'count' => $i,
  );
}