Fixed default value for audit_trail.fiscal_year column.
[fa-stable.git] / includes / db / audit_trail_db.inc
index 49abe1ca78bce27659eff9a381c179d368e259a9..c341a2f0d283c6ee171e4b177c414c9a647d07ff 100644 (file)
@@ -12,6 +12,8 @@
 
 function add_audit_trail($trans_type, $trans_no, $trans_date, $descr='')
 {
+       begin_transaction();
+
        $date = date2sql($trans_date);
        $sql = "INSERT INTO ".TB_PREF."audit_trail"
                . " (type, trans_no, user, gl_date, description)
@@ -20,7 +22,6 @@ function add_audit_trail($trans_type, $trans_no, $trans_date, $descr='')
                        . "'$date',". db_escape($descr). ")";
 
        db_query($sql, "Cannot add audit info");
-       
        // all audit records beside just inserted one should have gl_seq set to NULL
        // to avoid need for subqueries (not existing in MySQL 3) all over the code
        $sql = "UPDATE ".TB_PREF."audit_trail audit LEFT JOIN ".TB_PREF."fiscal_year year ON year.begin<='$date' AND year.end>='$date'
@@ -30,6 +31,7 @@ function add_audit_trail($trans_type, $trans_no, $trans_date, $descr='')
                . db_escape($trans_no);
 
        db_query($sql, "Cannot update audit gl_seq");
+       commit_transaction();
 }
 
 function get_audit_trail_all($trans_type, $trans_no)
@@ -76,17 +78,16 @@ function close_transactions($todate) {
 
        if (db_num_rows($result)) {
                $last_year = 0;
-               while ($row = db_fetch($result)) {
 
+               while ($row = db_fetch($result)) {
                        if ($row['fiscal_year'] == null) {
                                $errors = 1; continue;
                        }
-
                        if ($last_year != $row['fiscal_year']) {
                                $last_year = $row['fiscal_year'];
                                $counter = 0; // reset counter on fiscal year change
                        }
-                       
+
                        $seq = $row['closed'] ? ++$counter : 0;
                        if ($row['gl_seq'] != $seq)     { // update transaction status only when gl_seq has changed
                                $sql2 = "UPDATE ".TB_PREF."audit_trail SET"
@@ -96,6 +97,7 @@ function close_transactions($todate) {
                        }
                }
        }
+
        if ($errors) 
                display_warning(_("Some transactions journal GL postings were not indexed due to lack of audit trail record."));
        else
@@ -123,8 +125,7 @@ function is_closed_trans($type, $trans_no) {
 //             ." OR gl_seq>0)";
 
        $res = db_query($sql, "Cannot check transaction");
-       return db_num_rows($res);
 
+       return db_num_rows($res);
 }
 
-?>