X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=inline;f=admin%2Fdb%2Ffiscalyears_db.inc;h=29e826dc2cfde0cd65ca1ee835176a3551ae2d7f;hb=44abddfd180ec27cbd889f4c8c8f8271f6d6d19d;hp=a3133c933a46c54f8f2d8012526b47d20a9b5e92;hpb=c2d46f57e3b3becc9dceaa02a43cf85fd8c8789a;p=fa-stable.git diff --git a/admin/db/fiscalyears_db.inc b/admin/db/fiscalyears_db.inc index a3133c93..29e826dc 100644 --- a/admin/db/fiscalyears_db.inc +++ b/admin/db/fiscalyears_db.inc @@ -190,11 +190,16 @@ function delete_attachments_and_comments($type_no, $trans_no) $sql = "SELECT * FROM ".TB_PREF."attachments WHERE type_no = $type_no AND trans_no = $trans_no"; $result = db_query($sql, "Could not retrieve attachments"); + $delflag = false; while ($row = db_fetch($result)) { + $delflag = true; $dir = company_path(). "/attachments"; if (file_exists($dir."/".$row['unique_name'])) unlink($dir."/".$row['unique_name']); + } + if ($delflag) + { $sql = "DELETE FROM ".TB_PREF."attachments WHERE type_no = $type_no AND trans_no = $trans_no"; db_query($sql, "Could not delete attachment"); } @@ -341,6 +346,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 +356,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))