Improved error handling.
[fa-stable.git] / gl / includes / db / gl_db_banking.inc
index c6534fd6ae44413bc991dc948cf54aea424f2d7e..9d2a585d6e88187d054e1a0dd0cbf113be1abc4b 100644 (file)
@@ -87,6 +87,11 @@ function add_bank_transfer($from_account, $to_account, $date_,
        global $Refs, $SysPrefs;
        
        begin_transaction();
+       $args = func_get_args(); if (count($args) < 7) $args[] = 0;
+       $args = (object)array_combine(array('from_account', 'to_account', 'date_', 'amount',
+               'ref', 'memo_', 'charge'), $args);
+       $args->trans_no = 0;
+       hook_db_prewrite($args, ST_BANKTRANSFER);
 
        $trans_type = ST_BANKTRANSFER;
 
@@ -153,6 +158,8 @@ function add_bank_transfer($from_account, $to_account, $date_,
        $Refs->save($trans_type, $trans_no, $ref);
        add_audit_trail($trans_type, $trans_no, $date_);
 
+       $args->trans_no = $trans_no;
+       hook_db_postwrite($args, ST_BANKTRANSFER);
        commit_transaction();
 
        return $trans_no;
@@ -184,8 +191,14 @@ function write_bank_transaction($trans_type, $trans_no, $from_account, $items, $
        if ($use_transaction)
                begin_transaction();
 
+       $args = func_get_args(); if (count($args) < 11) $args[] = true;
+       $args = (object)array_combine(array('trans_type', 'trans_no', 'from_account', 'items', 'date_',
+               'person_type_id', 'person_id', 'person_detail_id', 'ref', 'memo_', 'use_transaction'),
+               $args);
+       hook_db_prewrite($args, $trans_type);
+
        if ($trans_no)
-               clear_bank_transaction($_SESSION['pay_items']->trans_type, $_SESSION['pay_items']->order_id, true);
+               clear_bank_transaction($_SESSION['pay_items']->trans_type, $_SESSION['pay_items']->order_id);
 
        $currency = get_bank_account_currency($from_account);
        $bank_gl_account = get_bank_gl_account($from_account);
@@ -216,7 +229,7 @@ function write_bank_transaction($trans_type, $trans_no, $from_account, $items, $
                $supp_amount = -$supp_amount;
 
                $trans_no = write_supp_trans($trans_type, $trans_no, $person_id, $date_, '',
-               $ref, "", $supp_amount, 0, 0);
+                       $ref, "", $supp_amount, 0, 0);
 
     }
     else
@@ -292,6 +305,8 @@ function write_bank_transaction($trans_type, $trans_no, $from_account, $items, $
        $Refs->save($trans_type, $trans_no, $ref);
        add_audit_trail($trans_type, $trans_no, $date_);
 
+       $args->trans_no = $trans_no;
+       hook_db_postwrite($args, $trans_type);
        if ($use_transaction)
                commit_transaction();
 
@@ -299,12 +314,10 @@ function write_bank_transaction($trans_type, $trans_no, $from_account, $items, $
 }
 //----------------------------------------------------------------------------------------
 
-function clear_bank_transaction($type, $type_no, $nested=false)
+function clear_bank_transaction($type, $type_no)
 {
-       global $Refs;
-       
-       if (!$nested)
-               begin_transaction();
+
+       hook_db_prevoid($type, $type_no);
 
        $sql = "DELETE FROM ".TB_PREF."bank_trans 
                WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no);
@@ -315,7 +328,6 @@ function clear_bank_transaction($type, $type_no, $nested=false)
 
        // in case it's a customer trans - probably better to check first
        void_cust_allocations($type, $type_no);
-       clear_customer_trans($type, $type_no);
 
        // in case it's a supplier trans - probably better to check first
        void_supp_allocations($type, $type_no);
@@ -324,8 +336,6 @@ function clear_bank_transaction($type, $type_no, $nested=false)
        clear_trans_tax_details($type, $type_no);
 
        delete_comments($type, $type_no);
-       if (!$nested)
-               commit_transaction();
 }
 
 ?>
\ No newline at end of file