Bugs in deleting fiscal year. Some transactions weren't deleted.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 9 Jan 2010 16:43:26 +0000 (16:43 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 9 Jan 2010 16:43:26 +0000 (16:43 +0000)
CHANGELOG.txt
admin/fiscalyears.php

index 556c5bb331df3a4658c8988f4c563edadf119a2f..393e7c716c7d89b21732c262917782cb5ec44741 100644 (file)
@@ -19,6 +19,10 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+09-Jan-2010 Joe Hunt
+# Bugs in deleting fiscal year. Some transactions weren't deleted.
+$ /admin/fiscalyear.php
+
 07-Jan-2010 Joe Hunt
 ! Changed to let the $doctypes in documents follow the types in types.inc
 + New document, Remittance, to print payment allocations to suppliers
index a974e4a2d2a09bdc4fc5343879cf81b4ff537e74..15f7ff41ad00161c23e335c2399915068287ab1b 100644 (file)
@@ -273,7 +273,7 @@ function delete_this_fiscalyear($selected_id)
                                db_query($sql, "Could not delete debtor trans");
                        }               
                }       
-               $sql = "DELETE FROM ".TB_PREF."cust_allocations WHERE trans_no_from = {$row['trans_no']} AND type_no_from = {$row['type']}";
+               $sql = "DELETE FROM ".TB_PREF."cust_allocations WHERE trans_no_from = {$row['trans_no']} AND trans_type_from = {$row['type']}";
                db_query($sql, "Could not delete cust allocations");
                $sql = "DELETE FROM ".TB_PREF."debtor_trans_details WHERE debtor_trans_no = {$row['trans_no']} AND debtor_trans_type = {$row['type']}";
                db_query($sql, "Could not delete debtor trans details");
@@ -286,7 +286,7 @@ function delete_this_fiscalyear($selected_id)
        $result = db_query($sql, "Could not retrieve supp trans");
        while ($row = db_fetch($result))
        {
-               $sql = "DELETE FROM ".TB_PREF."supp_allocations WHERE trans_no_from = {$row['trans_no']} AND type_no_from = {$row['type']}";
+               $sql = "DELETE FROM ".TB_PREF."supp_allocations WHERE trans_no_from = {$row['trans_no']} AND trans_type_from = {$row['type']}";
                db_query($sql, "Could not delete supp allocations");
                $sql = "DELETE FROM ".TB_PREF."supp_invoice_items WHERE supp_trans_no = {$row['trans_no']} AND supp_trans_type = {$row['type']}";
                db_query($sql, "Could not delete supp invoice items");
@@ -337,6 +337,7 @@ function delete_this_fiscalyear($selected_id)
        db_query($sql, "Could not delete exchange rates");
        $sql = "DELETE FROM ".TB_PREF."budget_trans WHERE tran_date <= '$to'";
        db_query($sql, "Could not delete exchange rates");
+       
        $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");
        while ($row = db_fetch($result))
@@ -345,23 +346,26 @@ function delete_this_fiscalyear($selected_id)
                db_query($sql, "Could not delete gl trans");
                if (is_account_balancesheet($row['account']))
                {
-                       $trans_no = get_next_trans_no(0);
-                       if (is_bank_account($row['account']))
-                       {
-                               $sql = "SELECT SUM(amount) FROM ".TB_PREF."bank_trans WHERE trans_date <= '$to' AND bank_act = '{$row['account']}'";
-                               $res = db_query($sql, "Could not retrieve bank trans");
-                               $row2 = db_fetch_row($res);
-                               $sql = "DELETE FROM ".TB_PREF."bank_trans WHERE trans_date <= '$to' AND bank_act = '{$row['account']}'";
-                               db_query($sql, "Could not delete bank trans");
-                               $sql = "INSERT INTO ".TB_PREF."bank_trans (type, trans_no, trans_date, bank_act, ref, amount) VALUES
-                                       (0, $trans_no, '$to', '{$row['account']}', '$ref', {$row2[0]})";
-                               db_query($sql, "Could not insert bank trans");
-                       }       
+                       $trans_no = get_next_trans_no(ST_JOURNAL);
                        $sql = "INSERT INTO ".TB_PREF."gl_trans (type, type_no, tran_date, account, memo_, amount) VALUES
-                               (0, $trans_no, '$to', '{$row['account']}', '$ref', {$row['amount']})";
+                               (ST_JOURNAL, $trans_no, '$to', '{$row['account']}', '$ref', {$row['amount']})";
                        db_query($sql, "Could not insert gl trans");
                }
        }
+       
+       $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))
+       {
+               $sql = "DELETE FROM ".TB_PREF."bank_trans WHERE trans_date <= '$to' AND bank_act = '{$row['bank_act']}'";
+               db_query($sql, "Could not delete bank trans");
+               $sql = "INSERT INTO ".TB_PREF."bank_trans (type, trans_no, trans_date, bank_act, ref, amount) VALUES
+                       (0, 0, '$to', '{$row['bank_act']}', '$ref', {$row['amount']})";
+               db_query($sql, "Could not insert bank trans");
+       }       
+       
+       $sql = "DELETE FROM ".TB_PREF."audit_trail WHERE gl_date <= '$to'";
+       db_query($sql, "Could not delete audit trail");
        delete_fiscalyear($selected_id);
        commit_transaction();   
 }
@@ -388,7 +392,7 @@ function display_fiscalyears()
 
        $result = get_all_fiscalyears();
        start_form();
-       display_note(_("Warning: During fiscal year removal all transactions 
+       display_note(_("Warning: Deleting a fiscal year all transactions 
                are removed and converted into relevant balances. This process is irreversible!"), 
                0, 0, "class='currentfg'");
        start_table($table_style);
@@ -423,7 +427,7 @@ function display_fiscalyears()
                if ($myrow["id"] != $company_year) {
                        delete_button_cell("Delete".$myrow['id'], _("Delete"));
                        submit_js_confirm("Delete".$myrow['id'],
-                               sprintf(_("Are you sure you want to remove fiscal year %s - %s? All transactions are removed and converted into relevant balances. Do you want to continue ?"), $from, $to));
+                               sprintf(_("Are you sure you want to delete fiscal year %s - %s? All transactions are deleted and converted into relevant balances. Do you want to continue ?"), $from, $to));
                } else
                        label_cell('');
                end_row();