Creation of audit trail and reference in GL was missing when deleting fiscal year.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 11 Jul 2011 07:28:14 +0000 (09:28 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 11 Jul 2011 07:28:14 +0000 (09:28 +0200)
admin/db/fiscalyears_db.inc

index a3133c933a46c54f8f2d8012526b47d20a9b5e92..c605c064d2b0aae5bd7abdf9d541ea1f304f99ee 100644 (file)
@@ -341,6 +341,7 @@ function delete_this_fiscalyear($selected_id)
        $sql = "SELECT account, SUM(amount) AS amount FROM ".TB_PREF."gl_trans WHERE tran_date <= '$to' GROUP by account";
        $result = db_query($sql, "Could not retrieve gl trans");
        $trans_no = get_next_trans_no(ST_JOURNAL);
+       $new = false;
        while ($row = db_fetch($result))
        {
                $sql = "DELETE FROM ".TB_PREF."gl_trans WHERE tran_date <= '$to' AND account = '{$row['account']}'";
@@ -350,9 +351,19 @@ function delete_this_fiscalyear($selected_id)
                        $sql = "INSERT INTO ".TB_PREF."gl_trans (type, type_no, tran_date, account, memo_, amount) VALUES
                                (".ST_JOURNAL.", $trans_no, '$to', '{$row['account']}', '$ref', {$row['amount']})";
                        db_query($sql, "Could not insert gl trans");
+                       $new = true;
                }
        }
-       
+       if ($new)
+       {
+               global $Refs;
+               $trans_type = ST_JOURNAL;
+               $reference = $Refs->get_next($trans_type);
+               $Refs->save($trans_type, $trans_no, $reference);
+               $date_ = sql2date($to);
+
+               add_audit_trail($trans_type, $trans_no, $date_);
+       }
        $sql = "SELECT bank_act, SUM(amount) AS amount FROM ".TB_PREF."bank_trans WHERE trans_date <= '$to' GROUP BY bank_act";
        $result = db_query($sql, "Could not retrieve bank trans");
        while ($row = db_fetch($result))