From 39de3e2b150d19e2d1c7fd9d12d0d7ddaf704343 Mon Sep 17 00:00:00 2001
From: Sam Hassell <sam@webzen.com.au>
Date: Thu, 3 Mar 2011 13:40:11 +0800
Subject: [PATCH 1/3] Initial commit to git.

---
 handlers/invoice_handler_field_invoice_delete.inc  |   67 ++++
 handlers/invoice_handler_field_invoice_edit.inc    |   74 ++++
 handlers/invoice_handler_field_invoice_number.inc  |   39 ++
 .../invoice_handler_field_invoice_paid_toggle.inc  |   74 ++++
 .../invoice_handler_field_invoice_pay_status.inc   |   67 ++++
 handlers/invoice_handler_field_invoice_total.inc   |   30 ++
 ...invoice_handler_filter_invoice_company_name.inc |   14 +
 invoice.views.inc                                  |  393 ++++++++++++++++++++
 8 files changed, 758 insertions(+), 0 deletions(-)
 create mode 100644 handlers/invoice_handler_field_invoice_delete.inc
 create mode 100644 handlers/invoice_handler_field_invoice_edit.inc
 create mode 100644 handlers/invoice_handler_field_invoice_number.inc
 create mode 100644 handlers/invoice_handler_field_invoice_paid_toggle.inc
 create mode 100644 handlers/invoice_handler_field_invoice_pay_status.inc
 create mode 100644 handlers/invoice_handler_field_invoice_total.inc
 create mode 100644 handlers/invoice_handler_filter_invoice_company_name.inc
 create mode 100644 invoice.views.inc

diff --git a/handlers/invoice_handler_field_invoice_delete.inc b/handlers/invoice_handler_field_invoice_delete.inc
new file mode 100644
index 0000000..9f2a8e8
--- /dev/null
+++ b/handlers/invoice_handler_field_invoice_delete.inc
@@ -0,0 +1,67 @@
+<?php
+// $Id$
+/**
+ * Field handler to present invoice pay status.
+ */
+class invoice_handler_field_invoice_delete extends views_handler_field {
+  function construct() {
+    parent::construct();
+    $this->additional_fields['invoice_invoices_pay_limit'] = array('table' => 'invoice_invoices', 'field' => 'pay_limit');
+    $this->additional_fields['node_created'] = array('table' => 'node', 'field' => 'created');    
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['output_type'] = array('default' => FALSE);    
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['output_type'] = array(
+      '#type' => 'select',
+      '#title' => t('Output Type'),
+      '#options' => array(
+        'text' => t('Text'),
+        'icon' => t('Icon'),
+      ),
+      '#description' => t('Select whether the output should be text (paid,unpaid) or an icon.'),
+      '#default_value' => !empty($this->options['output_type']),
+    );
+  }
+
+  function query() {
+    $this->ensure_my_table();
+    $this->field_alias = $this->query->add_field($this->table_alias, $this->real_field);    
+    $this->add_additional_fields();
+  }
+
+  function render($values) {
+  
+    // Check if invoice has pay limit, if yes see if the date exceeded it
+    if ($values->invoice_invoices_pay_status == 'unpaid' && $values->invoice_invoices_pay_limit > 0) {
+      if (mktime(0, 0, 0, date('m'), date('d'), date('Y')) > $values->node_created + (86400 * $values->invoice_invoices_pay_limit)) {
+         //$pay_status = _
+         $values->invoice_invoices_pay_status = 'overdue';
+      }
+    }
+  
+    if ($this->options['output_type'] == 'icon') {
+      switch($values->invoice_invoices_pay_status) {
+        case 'paid':
+          $pay_status = _invoice_get_icon('bullet_green', NULL, array('title' => t('Paid')));
+          break;
+        case 'unpaid':
+          $pay_status = _invoice_get_icon('bullet_yellow', NULL, array('title' => t('Unpaid'))); 
+          break;
+        case 'overdue':
+          $pay_status = _invoice_get_icon('bullet_red', NULL, array('title' => t('Overdue')));
+          break;
+      }
+    }
+    else {
+      $pay_status = $values->invoice_invoices_pay_status;
+    }     
+    return $pay_status;
+  }
+}
diff --git a/handlers/invoice_handler_field_invoice_edit.inc b/handlers/invoice_handler_field_invoice_edit.inc
new file mode 100644
index 0000000..860bbf4
--- /dev/null
+++ b/handlers/invoice_handler_field_invoice_edit.inc
@@ -0,0 +1,74 @@
+<?php
+// $Id$
+/**
+ * Field handler to provide invoice edit link..
+ */
+class invoice_handler_field_invoice_edit extends views_handler_field {
+  function construct() {
+    parent::construct();
+    $this->additional_fields['invoice_invoices_pay_limit'] = array('table' => 'invoice_invoices', 'field' => 'pay_limit');
+    $this->additional_fields['invoice_invoices_iid'] = array('table' => 'invoice_invoices', 'field' => 'iid');    
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['output_type'] = array('default' => FALSE);    
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['output_type'] = array(
+      '#type' => 'select',
+      '#title' => t('Output Type'),
+      '#options' => array(
+        'text' => t('Text'),
+        'icon' => t('Icon'),
+      ),
+      '#description' => t('Select whether the output should be text or an icon.'),
+      '#default_value' => !empty($this->options['output_type']),
+    );
+  }
+
+  function query() {
+    $this->ensure_my_table();
+    $this->add_additional_fields();
+  }
+
+  function render($values) {
+    if (user_access('administer invoices')) {
+      if ($values->invoice_invoices_pay_status != 'paid') {
+        $destination = 'invoice/set/pay_status/'. $values->invoice_invoices_iid .'/paid/'. _invoice_getvars_array_to_string($_GET);
+        $toggle = $this->get_toggle_icon('accept', $destination, array('title' => t('Set paid')));
+      }
+      else {
+        $destination = 'invoice/set/pay_status/'. $values->invoice_invoices_iid .'/unpaid/'. _invoice_getvars_array_to_string($_GET);
+        $toggle = $this->get_toggle_icon('coins_delete', $destination, array('title' => t('Set unpaid')));
+      }
+    }
+   return $toggle;
+  }
+  
+  /**
+   * Helper function to get an icon
+   */
+  function get_toggle_icon($name, $url = NULL, $attributes = array(), $extension = 'png') {
+    if (empty($attributes['alt'])) {
+      $attributes['alt'] = $attributes['title'];
+    }
+    
+    $img_addition = '';
+    foreach ($attributes as $key => $value) {
+      $img_addition .= ' '. $key .'="'. $value .'"';
+    }
+    
+    $icon = '<img src="'. base_path() . drupal_get_path('module', 'invoice') .'/images/'. $name .'.'. $extension .'"'. $img_addition .' />';
+    if (!empty($url)) {
+      $icon = l($icon, $url, array('html' => TRUE, 'query' => array('destination' => 'test')));
+      $icon = '<a href="'. base_path() . $url .'" '. drupal_attributes($attributes) .'>'. $icon .'</a>';
+    }
+    
+    return $icon;
+  }
+  
+}
diff --git a/handlers/invoice_handler_field_invoice_number.inc b/handlers/invoice_handler_field_invoice_number.inc
new file mode 100644
index 0000000..c9c99a4
--- /dev/null
+++ b/handlers/invoice_handler_field_invoice_number.inc
@@ -0,0 +1,39 @@
+<?php
+// $Id$
+/**
+ * Field handler to present an invoices number..
+ */
+class invoice_handler_field_invoice_number extends views_handler_field {
+  function construct() {
+    parent::construct();
+    $this->additional_fields['iid'] = array('table' => 'invoice_invoices', 'field' => 'iid');
+    $this->additional_fields['nid'] = array('table' => 'node', 'field' => 'nid');
+    
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['link_to_node'] = array('default' => '', 'translatable' => TRUE);
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['link_to_node'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Link to Node'),
+      '#default_value' => $this->options['link_to_node'],
+      '#description' => t('Check this box to link the invoice number to the node.'),
+    );
+  }
+
+  function query() {
+    $this->ensure_my_table();
+    $this->add_additional_fields();
+  }
+
+  function render($values) {
+    $invoice_number =  _invoice_get_formatted_invoice_number($values->invoice_invoices_iid);
+    return ($this->options['link_to_node']) ? l($invoice_number, 'node/'. $values->nid) : $invoice_number;
+  }
+}
diff --git a/handlers/invoice_handler_field_invoice_paid_toggle.inc b/handlers/invoice_handler_field_invoice_paid_toggle.inc
new file mode 100644
index 0000000..9b2f8d4
--- /dev/null
+++ b/handlers/invoice_handler_field_invoice_paid_toggle.inc
@@ -0,0 +1,74 @@
+<?php
+// $Id$
+/**
+ * Field handler to present invoice pay status toggle.
+ */
+class invoice_handler_field_invoice_paid_toggle extends views_handler_field {
+  function construct() {
+    parent::construct();
+    $this->additional_fields['invoice_invoices_pay_limit'] = array('table' => 'invoice_invoices', 'field' => 'pay_limit');
+    $this->additional_fields['invoice_invoices_iid'] = array('table' => 'invoice_invoices', 'field' => 'iid');    
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['output_type'] = array('default' => FALSE);    
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['output_type'] = array(
+      '#type' => 'select',
+      '#title' => t('Output Type'),
+      '#options' => array(
+        'text' => t('Text'),
+        'icon' => t('Icon'),
+      ),
+      '#description' => t('Select whether the output should be text or an icon.'),
+      '#default_value' => !empty($this->options['output_type']),
+    );
+  }
+
+  function query() {
+    $this->ensure_my_table();
+    $this->add_additional_fields();
+  }
+
+  function render($values) {
+    if (user_access('administer invoices')) {
+      if ($values->invoice_invoices_pay_status != 'paid') {
+        $destination = 'invoice/set/pay_status/'. $values->invoice_invoices_iid .'/paid/'. _invoice_getvars_array_to_string($_GET);
+        $toggle = $this->get_toggle_icon('accept', $destination, array('title' => t('Set paid')));
+      }
+      else {
+        $destination = 'invoice/set/pay_status/'. $values->invoice_invoices_iid .'/unpaid/'. _invoice_getvars_array_to_string($_GET);
+        $toggle = $this->get_toggle_icon('coins_delete', $destination, array('title' => t('Set unpaid')));
+      }        
+    }
+   return $toggle;
+  }
+  
+  /**
+   * Helper function to get an icon
+   */
+  function get_toggle_icon($name, $url = NULL, $attributes = array(), $extension = 'png') {
+    if (empty($attributes['alt'])) {
+      $attributes['alt'] = $attributes['title'];
+    }
+    
+    $img_addition = '';
+    foreach ($attributes as $key => $value) {
+      $img_addition .= ' '. $key .'="'. $value .'"';
+    }
+    
+    $icon = '<img src="'. base_path() . drupal_get_path('module', 'invoice') .'/images/'. $name .'.'. $extension .'"'. $img_addition .' />';
+    if (!empty($url)) {
+      $icon = l($icon, $url, array('html' => TRUE, 'query' => array('destination' => 'test')));
+      $icon = '<a href="'. base_path() . $url .'" '. drupal_attributes($attributes) .'>'. $icon .'</a>';
+    }
+    
+    return $icon;
+  }
+  
+}
diff --git a/handlers/invoice_handler_field_invoice_pay_status.inc b/handlers/invoice_handler_field_invoice_pay_status.inc
new file mode 100644
index 0000000..bf28ab3
--- /dev/null
+++ b/handlers/invoice_handler_field_invoice_pay_status.inc
@@ -0,0 +1,67 @@
+<?php
+// $Id$
+/**
+ * Field handler to present invoice pay status.
+ */
+class invoice_handler_field_invoice_pay_status extends views_handler_field {
+  function construct() {
+    parent::construct();
+    $this->additional_fields['invoice_invoices_pay_limit'] = array('table' => 'invoice_invoices', 'field' => 'pay_limit');
+    $this->additional_fields['node_created'] = array('table' => 'node', 'field' => 'created');    
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['output_type'] = array('default' => FALSE);    
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['output_type'] = array(
+      '#type' => 'select',
+      '#title' => t('Output Type'),
+      '#options' => array(
+        'text' => t('Text'),
+        'icon' => t('Icon'),
+      ),
+      '#description' => t('Select whether the output should be text (paid,unpaid) or an icon.'),
+      '#default_value' => !empty($this->options['output_type']),
+    );
+  }
+
+  function query() {
+    $this->ensure_my_table();
+    $this->field_alias = $this->query->add_field($this->table_alias, $this->real_field);    
+    $this->add_additional_fields();
+  }
+
+  function render($values) {
+  
+    // Check if invoice has pay limit, if yes see if the date exceeded it
+    if ($values->invoice_invoices_pay_status == 'unpaid' && $values->invoice_invoices_pay_limit > 0) {
+      if (mktime(0, 0, 0, date('m'), date('d'), date('Y')) > $values->node_created + (86400 * $values->invoice_invoices_pay_limit)) {
+         //$pay_status = _
+         $values->invoice_invoices_pay_status = 'overdue';
+      }
+    }
+  
+    if ($this->options['output_type'] == 'icon') {
+      switch($values->invoice_invoices_pay_status) {
+        case 'paid':
+          $pay_status = _invoice_get_icon('bullet_green', NULL, array('title' => t('Paid')));
+          break;
+        case 'unpaid':
+          $pay_status = _invoice_get_icon('bullet_yellow', NULL, array('title' => t('Unpaid'))); 
+          break;
+        case 'overdue':
+          $pay_status = _invoice_get_icon('bullet_red', NULL, array('title' => t('Overdue')));
+          break;
+      }
+    }
+    else {
+      $pay_status = $values->invoice_invoices_pay_status;
+    }     
+    return $pay_status;
+  }
+}
diff --git a/handlers/invoice_handler_field_invoice_total.inc b/handlers/invoice_handler_field_invoice_total.inc
new file mode 100644
index 0000000..6b816f7
--- /dev/null
+++ b/handlers/invoice_handler_field_invoice_total.inc
@@ -0,0 +1,30 @@
+<?php
+// $Id$
+/**
+ * Field handler to present invoice totals.
+ */
+class invoice_handler_field_invoice_total extends views_handler_field {
+  function construct() {
+    parent::construct();
+    $this->additional_fields['iid'] = array('table' => 'invoice_invoices', 'field' => 'iid');
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+  }
+
+  function query() {
+    $this->ensure_my_table();
+    $this->add_additional_fields();
+  }
+
+  function render($values) {
+    $totals =_invoice_get_invoice_totals($values->invoice_invoices_iid);
+    return check_plain(_invoice_round_and_format_money($totals[$this->field]));
+  }
+}
diff --git a/handlers/invoice_handler_filter_invoice_company_name.inc b/handlers/invoice_handler_filter_invoice_company_name.inc
new file mode 100644
index 0000000..2a07f54
--- /dev/null
+++ b/handlers/invoice_handler_filter_invoice_company_name.inc
@@ -0,0 +1,14 @@
+<?php
+// $Id$
+/**
+ * Filter handler for company name.
+ */
+class invoice_handler_filter_invoice_company_name extends views_handler_filter_many_to_one {
+  function get_value_options() {
+    $result = db_query("SELECT DISTINCT company_name FROM {invoice_customers}");
+    while ($row = db_fetch_array($result)) {
+      $options[$row['company_name']] = $row['company_name'];
+    }
+    $this->value_options = $options;
+  }
+}
diff --git a/invoice.views.inc b/invoice.views.inc
new file mode 100644
index 0000000..2505a6e
--- /dev/null
+++ b/invoice.views.inc
@@ -0,0 +1,393 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * 
+ * Invoice module views integration.
+ */
+
+/**
+ * Implementation of hook_views_handlers().
+ */
+function invoice_views_handlers() {
+  return array(
+    'info' => array(
+      'path' => drupal_get_path('module', 'invoice') . '/handlers',
+    ),
+    // Field handlers.
+    'handlers' => array(
+      'invoice_handler_field_invoice_total' => array(
+        'parent' => 'views_handler_field',
+      ),
+      'invoice_handler_field_invoice_number' => array(
+        'parent' => 'views_handler_field',
+      ),
+      'invoice_handler_field_invoice_pay_status' => array(
+        'parent' => 'views_handler_field',
+      ),
+      'invoice_handler_field_invoice_paid_toggle' => array(
+        'parent' => 'views_handler_field',
+      ),                            
+      // Filter handlers.
+      'invoice_handler_filter_invoice_company_name' => array(
+        'parent' => 'views_handler_filter_many_to_one',
+      ),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_views_data().
+ */
+function invoice_views_data() {
+  $data['invoice_invoices']['table']['group'] = t('Invoice');
+
+  /* Invoice_invoices table. */
+  
+  $data['invoice_invoices']['table']['join'] = array(
+    // Join to node table.
+    'node' => array(
+      'left_field' => 'nid',
+      'field' =>  'nid',
+      'type' => 'INNER',
+    ),
+    // Join to customers table.
+    'invoice_customers' => array(
+      'left_field' => 'invoice_id',
+      'field' => 'iid',
+      'type' => 'INNER',
+    ),
+  );
+
+  // Fields.
+  
+  $data['invoice_invoices']['iid'] = array(
+    'title' => t('Id'),
+    'help' => t('The primary key'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
+  $data['invoice_invoices']['pay_status'] = array(
+    'title' => t('Payment Status'),
+    'help' => t('Whether the invoice has been paid.'),
+    'field' => array(
+      'handler' => 'invoice_handler_field_invoice_pay_status',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
+  $data['invoice_invoices']['pay_limit'] = array(
+    'title' => t('Payment Limit'),
+    'help' => t('The amount of days from issue the invoice must be paid.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
+  $data['invoice_invoices']['description'] = array(
+    'title' => t('Description'),
+    'help' => t('Short description of the invoice.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => FALSE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+  
+  // Aliases.
+  
+  $data['invoice_invoices']['invoice_number'] = array(
+    'field' => array(
+      'title' => t('Invoice Number'),
+      'help' => t('The invoice\'s identifing number.'),
+      'handler' => 'invoice_handler_field_invoice_number',
+    ),
+  );
+  
+  $data['invoice_invoices']['inctotal'] = array(
+    'field' => array(
+      'title' => t('Total Including VAT'),
+      'help' => t('The invoice\'s total including VAT.'),
+      'handler' => 'invoice_handler_field_invoice_total',
+    ),
+  );
+  $data['invoice_invoices']['extotal'] = array(
+    'field' => array(
+      'title' => t('Total excluding VAT'),
+      'help' => t('The invoice\'s total excluding VAT.'),
+      'handler' => 'invoice_handler_field_invoice_total',
+    ),
+  );
+  $data['invoice_invoices']['vattotal'] = array(
+    'field' => array(
+      'title' => t('VAT Total'),
+      'help' => t('The total VAT charged on the invoice.'),
+      'handler' => 'invoice_handler_field_invoice_total',
+    ),
+  );    
+  $data['invoice_invoices']['paid_toggle'] = array(
+    'field' => array(
+      'title' => t('Toggle Status'),
+      'help' => t('A link to toggle the paid status of the invoice.'),
+      'handler' => 'invoice_handler_field_invoice_paid_toggle',
+    ),
+  );    
+  
+  /* Invoice_customers table. */
+
+  $data['invoice_customers']['table']['group'] = t('Invoice');
+
+  // Join to invoice_invoices table.
+  $data['invoice_customers']['table']['join'] = array(
+    'node' => array(
+      'table' => 'invoice_customers',
+      'left_table' => 'invoice_invoices',
+      'left_field' => 'iid',
+      'field' =>  'invoice_id',
+      'type' => 'INNER',
+    ),
+  );
+
+  // Fields.
+  
+  $data['invoice_customers']['company_name'] = array(
+    'title' => t('Company Name'),
+    'help' => t('The customer\'s company name.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'invoice_handler_filter_invoice_company_name',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+  
+  $data['invoice_customers']['vat_number'] = array(
+    'title' => t('VAT Number'),
+    'help' => t('The customer\'s VAT number.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+  
+  $data['invoice_customers']['first_name'] = array(
+    'title' => t('First Name'),
+    'help' => t('The customer\'s first name.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
+  $data['invoice_customers']['last_name'] = array(
+    'title' => t('Last Name'),
+    'help' => t('The customer\'s last name.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+  
+  $data['invoice_customers']['street'] = array(
+    'title' => t('Street'),
+    'help' => t('The customer\'s street.'),
+    'field' => array(    
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+  
+  $data['invoice_customers']['building_number'] = array(
+    'title' => t('Building number'),
+    'help' => t('The customer\'s building number.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
+  $data['invoice_customers']['zipcode'] = array(
+    'title' => t('Zip Code'),
+    'help' => t('The customer\'s zipcode.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
+  $data['invoice_customers']['city'] = array(
+    'title' => t('City'),
+    'help' => t('The customer\'s city.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
+  $data['invoice_customers']['country'] = array(
+    'title' => t('Country'),
+    'help' => t('The customer\'s country.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
+  $data['invoice_customers']['coc_number'] = array(
+    'title' => t('COC Number'),
+    'help' => t('The customer\'s COC Number.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );  
+  
+  
+  $data['invoice_customers']['description'] = array(
+    'title' => t('Customer\'s Description'),
+    'help' => t('The customer\'s description.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ), 
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ), 
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  ); 
+  
+  return $data;
+}
-- 
1.7.1


From 812779ff6854021b3b279ac713b2fc08d450ffa2 Mon Sep 17 00:00:00 2001
From: Sam Hassell <sam@webzen.com.au>
Date: Thu, 3 Mar 2011 13:41:16 +0800
Subject: [PATCH 2/3] Forgot to add invoice.module, remedied.

---
 invoice.module |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/invoice.module b/invoice.module
index d33af89..dd75a9c 100755
--- a/invoice.module
+++ b/invoice.module
@@ -801,7 +801,9 @@ function invoice_set_pay_status($invoice_number, $status) {
   
   $a_query_vars = _invoice_getvars_string_to_array($query_string);
 
-  drupal_goto('invoices', $a_query_vars);
+  $destination = isset($_GET['destination']) ? $_GET['destination'] : 'invoices';
+
+  drupal_goto($destination, $a_query_vars);
 }
 
 /**
@@ -954,3 +956,15 @@ function theme_invoice_table($header, $rows, $attributes = array(), $caption = N
   $output .= "</table>\n";
   return $output;
 }
+
+
+/**
+ * Implementation of hook_views_api().
+ */
+function invoice_views_api() {
+  return array(
+    'api' => 2,
+  );
+}
+
+
-- 
1.7.1


From 94aa4d44d8e440a8a960bff183798cc61c3ecb19 Mon Sep 17 00:00:00 2001
From: Sam Hassell <sam@webzen.com.au>
Date: Thu, 3 Mar 2011 13:59:50 +0800
Subject: [PATCH 3/3] Changed money format code to use _invoice_round.

---
 handlers/invoice_handler_field_invoice_total.inc |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/handlers/invoice_handler_field_invoice_total.inc b/handlers/invoice_handler_field_invoice_total.inc
index 6b816f7..5fae5ff 100644
--- a/handlers/invoice_handler_field_invoice_total.inc
+++ b/handlers/invoice_handler_field_invoice_total.inc
@@ -25,6 +25,8 @@ class invoice_handler_field_invoice_total extends views_handler_field {
 
   function render($values) {
     $totals =_invoice_get_invoice_totals($values->invoice_invoices_iid);
-    return check_plain(_invoice_round_and_format_money($totals[$this->field]));
+    $total = _invoice_round($totals[$this->field]);
+    $total = money_format('%.2n', $total);
+    return check_plain($total);
   }
 }
-- 
1.7.1

