X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Fdb%2Ffiscalyears_db.inc;h=ec00e0677db1ae283ca0d66362db1eb6dfefbab0;hb=50606312fee0bb0dbe984e2c08af53b7dab229bd;hp=b14ce5bad49527f0579292e92d545c9c6bf5cef7;hpb=8f8e4c4823dd07c604ade72529e7a4dda5f98996;p=fa-stable.git diff --git a/admin/db/fiscalyears_db.inc b/admin/db/fiscalyears_db.inc index b14ce5ba..ec00e067 100644 --- a/admin/db/fiscalyears_db.inc +++ b/admin/db/fiscalyears_db.inc @@ -166,10 +166,6 @@ function open_year($year) { $myrow = get_fiscalyear($year); $from = sql2date($myrow['begin']); - - begin_transaction(); - open_transactions($from); - commit_transaction(); } //--------------------------------------------------------------------------------------------- @@ -326,17 +322,25 @@ function delete_this_fiscalyear($selected_id) $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"; + $sql = "SELECT account, SUM(amount) AS amount, person_type_id, person_id FROM " + .TB_PREF."gl_trans WHERE tran_date <= '$to' GROUP by account, person_type_id, person_id"; $result = db_query($sql, "Could not retrieve gl trans"); $trans_no = get_next_trans_no(ST_JOURNAL); + + $last_account=''; while ($row = db_fetch($result)) { - $sql = "DELETE FROM ".TB_PREF."gl_trans WHERE tran_date <= '$to' AND account = '{$row['account']}'"; - db_query($sql, "Could not delete gl trans"); - if (is_account_balancesheet($row['account'])) + if ($last_account != $row['account']) // deletes all subledgers postings, so do it once for account + { + $sql = "DELETE FROM ".TB_PREF."gl_trans WHERE tran_date <= '$to' AND account = '{$row['account']}'"; + db_query($sql, "Could not delete gl trans"); + $last_account = $row['account']; + } + if (is_account_balancesheet($row['account']) && $row['amount']) { - $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']})"; + $sql = "INSERT INTO ".TB_PREF."gl_trans (type, type_no, tran_date, account, memo_, amount, person_type_id, person_id) VALUES + (".ST_JOURNAL.", $trans_no, '$to', '{$row['account']}', '$ref', {$row['amount']}, " + .db_escape($row['person_type_id'], true).", ".db_escape($row['person_id'], true).")"; db_query($sql, "Could not insert gl trans"); } }