X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Fdb%2Ffiscalyears_db.inc;h=c605c064d2b0aae5bd7abdf9d541ea1f304f99ee;hb=5d3fcb9c57e586c20651594edf91a2dccb08df00;hp=b14ce5bad49527f0579292e92d545c9c6bf5cef7;hpb=46c5f7a65a7659a44ae8254c63152074363d3987;p=fa-stable.git diff --git a/admin/db/fiscalyears_db.inc b/admin/db/fiscalyears_db.inc index b14ce5ba..c605c064 100644 --- a/admin/db/fiscalyears_db.inc +++ b/admin/db/fiscalyears_db.inc @@ -81,6 +81,18 @@ function is_date_in_fiscalyears($date, $closed=true) return db_fetch($result) !== false; } +function get_fiscalyear_begin_for_date($date) +{ + $date = date2sql($date); + $sql = "SELECT begin FROM ".TB_PREF."fiscal_year WHERE '$date' >= begin AND '$date' <= end"; + $result = db_query($sql, "could not get begin date of the fiscal year"); + $row = db_fetch_row($result); + if ($row != false) + return sql2date($row[0]); + else + return begin_fiscalyear(); +} + function check_begin_end_date($date1, $date2) { $sql = "SELECT MAX(end), MIN(begin) FROM ".TB_PREF."fiscal_year"; @@ -329,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']}'"; @@ -338,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))