X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Fdb%2Ffiscalyears_db.inc;h=6281268ba897d0be203511edd2b801f00836badf;hb=11bd0b6c67394ca6cdb0e71078d40bad262986ca;hp=893233c4120e825240bb44e30d1566a3f5e87df0;hpb=60d0cd5ddc5baa456ca89672686569f154a63045;p=fa-stable.git diff --git a/admin/db/fiscalyears_db.inc b/admin/db/fiscalyears_db.inc index 893233c4..6281268b 100644 --- a/admin/db/fiscalyears_db.inc +++ b/admin/db/fiscalyears_db.inc @@ -322,8 +322,9 @@ function delete_this_fiscalyear($selected_id) db_query($sql, "Could not delete workorders"); delete_attachments_and_comments(ST_WORKORDER, $row['id']); } - $sql = "SELECT loc_code, stock_id, SUM(qty) AS qty, SUM(qty*standard_cost) AS std_cost FROM ".TB_PREF."stock_moves WHERE tran_date <= '$to' GROUP by - loc_code, stock_id"; + $sql = "SELECT loc_code, stock_id, SUM(qty) AS qty," + ." SUM(-qty*IF(type=".ST_SUPPRECEIVE." OR type=".ST_SUPPCREDIT.", price, standard_cost)) AS std_cost" + ." FROM ".TB_PREF."stock_moves WHERE tran_date <= '$to' GROUP by loc_code, stock_id"; $result = db_query($sql, "Could not retrieve stock moves"); while ($row = db_fetch($result)) { @@ -350,6 +351,7 @@ function delete_this_fiscalyear($selected_id) $last_account=''; $new = false; + $total = 0.0; while ($row = db_fetch($result)) { if ($last_account != $row['account']) // deletes all subledgers postings, so do it once for account @@ -364,6 +366,8 @@ function delete_this_fiscalyear($selected_id) (".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"); + if ($row['amount'] > 0.0) + $total += $row['amount']; $new = true; } }