Hi you all.

Here you have a piece of code to be included on storminvoice.module which offers a drupal block with last 10 pending invoices. I've code it for the storm drupal 5 version but I guess it could work on 6 without many changes (if any). It has been inspired on stormtickets block and it may be helpful for top storm page and for main invoices list page.

<?php
function storminvoice_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $block[0]['info'] = t('Pending Invoices');
      break;
    case 'view':
      if ($delta == 0) {
        $block['subject'] = t('Pending Invoices');
        $block['content'] = storminvoice_blocklist();
      }
      break;
  }
  return $block;
}

function storminvoice_blocklist($output=FALSE) {
  if (!user_access('Storm invoice: access')) return;

  drupal_add_js(drupal_get_path('module', 'storminvoice') .'/storminvoice.js', 'module', 'header', FALSE);
  $status_list = stormattribute_attributes_bydomain('invoices status search');
  $rstatus_list = array_flip($status_list);
  $ticketstatus = $rstatus_list['open'];

  $s  = "SELECT n.nid, n.title, n.changed, inv.duedate, inv.number, inv.amount
          FROM {node} AS n
          INNER JOIN {storminvoice} AS inv ON n.vid=inv.vid
        WHERE n.status=1 AND n.type='storminvoice'";
  //$where[] = "inv.paymentdate=0 AND inv.duedate>". time();
  $where[] = "inv.paymentdate=0";
  $s = db_rewrite_sql($s);
  $r = pager_query(stormticket_access_sql($s, $where) .' ORDER BY n.changed', 10, 0, NULL);

  $header = array(
    array(
      'data' => t('Ref'),
    ),
    array(
      'data' => t('Amount'),
    ),
  );

  $rows = array();
  $invoices = array();
  while ($item = db_fetch_object($r)) {
    $invoices[] = $item;
    $rows[] = array(
      l($item->number, 'node/'. $item->nid).'<br/>'.$item->title,
      $item->amount,
    );
  }

  $o = theme('table', $header, $rows);
  if (!$rows) {
    $o = t('No pending invoices by now.');
    return $o;
  }
  else {
    return $o;
  }
}
?>

Comments

Magnity’s picture

Status: Active » Closed (won't fix)

Development has stopped on the 5.x branch (see #410784: Looking for a new maintainer), so I am marking this as "Won't Fix".

If the issue also affects the 6.x branch please reopen under that category.