--- balance_tracker.module	2011-02-25 04:11:21.000000000 +0200
+++ modded_balance_tracker.module	2011-03-14 21:11:40.000000000 +0200
@@ -307,7 +307,7 @@ function balance_tracker_adjustment_form
  */
 function balance_tracker_adjustment_form_submit($form, &$form_state) {
   $account = user_load(array('name' => $form_state['values']['username'], 'status' => 1));
-  _balance_tracker_create_entry($account->uid, $form_state['values']['type'], $form_state['values']['amount'], check_plain($form_state['values']['message']));
+  _balance_tracker_create_entry($account->uid, $form_state['values']['type'], $form_state['values']['amount'], array('message'=>check_plain($form_state['values']['message'])));
   drupal_set_message(t('Transaction Success: Account balance adjusted successfully.'));
   drupal_goto('user/'. $account->uid .'/balance');
 }
@@ -537,15 +537,17 @@ function balance_tracker_balance_table($
  *   The UID of the user the credit should be applied to.
  * @param $amount
  *   The amount to credit the account with.
- * @param $message
- *   A string explaining the nature of the credit. (ie, 'Commission for $27
+ * @param $data
+ *   An array containing extra data of the made credit. Balance Tracker core provides only
+ *   message data. Other modules can extend functionality via this array.
+ *   Message: A string explaining the nature of the credit. (ie, 'Commission for $27
  *   purchase')
  *
  * @return
  *   A boolean reflecting whether the transaction was successful.
  */
-function balance_tracker_credit_account($uid, $amount, $message) {
-  return _balance_tracker_create_entry($uid, 'credit', $amount, $message);
+function balance_tracker_credit_account($uid, $amount, $data) {
+  return _balance_tracker_create_entry($uid, 'credit', $amount, $data);
 }
 
 /**
@@ -555,24 +557,26 @@ function balance_tracker_credit_account(
  *   The UID of the user the debit should be applied to.
  * @param $amount
  *   The amount to debit the account.
- * @param $message
- *   A string explaining the nature of the debit. (ie, 'Monthly account fees')
+ * @param $data
+ *   An array containing extra data of the made debit. Balance Tracker core provides only
+ *   message data. Other modules can extend functionality via this array.
+ *   Message: A string explaining the nature of the debit. (ie, 'Monthly account fees')
  *
  * @return
  *   A boolean reflecting whether the transaction was successful.
  */
-function balance_tracker_debit_account($uid, $amount, $message) {
-  return _balance_tracker_create_entry($uid, 'debit', $amount, $message);
+function balance_tracker_debit_account($uid, $amount, $data) {
+  return _balance_tracker_create_entry($uid, 'debit', $amount, $data);
 }
 
 /**
  * Helper function to handle the actual account transactions.
  */
-function _balance_tracker_create_entry($uid, $type, $amount, $message) {
+function _balance_tracker_create_entry($uid, $type, $amount, $data = array()) {
   $balance = balance_tracker_get_balance($uid);
  
   // Invoke any hook_balance_prewrite() implementations.
-  module_invoke_all('balance_prewrite', $uid, $type, $amount, $message);
+  module_invoke_all('balance_prewrite', $uid, $type, $amount, $data);
 
   if ($type == 'credit') {
     $balance += (float)$amount;
@@ -580,13 +584,15 @@ function _balance_tracker_create_entry($
   else {
     $balance -= (float)$amount;
   }
-  $success = db_query("INSERT INTO {balance_items} (uid, timestamp, type, message, amount, balance) VALUES (%d, %d, '%s', '%s', %f, %f)", $uid, $_SERVER['REQUEST_TIME'], $type, $message, (float)$amount, $balance);
+  $success = db_query("INSERT INTO {balance_items} (uid, timestamp, type, message, amount, balance) VALUES (%d, %d, '%s', '%s', %f, %f)", $uid, $_SERVER['REQUEST_TIME'], $type, $data['message'], (float)$amount, $balance);
+  // get the latest added id for reference to other modules
+  $bid = db_last_insert_id('balance_items','bid');
 
   // db_query only returns a boolean false if the query fails. Therefore, we need to check if it is a boolean
   // *and* if it is false to determine what to returns.
   if ($success !== FALSE) {
     // Invoke any hook_balance_write() implementations.
-    module_invoke_all('balance_write', $uid, $type, $amount, $message);
+    module_invoke_all('balance_write', $bid, $uid, $type, $amount, $data);
     return TRUE;
   }
   else {
