New report included in core, Costed Inventory Movement Report (rep308.php).
[fa-stable.git] / admin / db / transactions_db.inc
index 594c34d23622216c87c738a0357cc1c72af1d371..8eb12130daea2591aa943b6d77dbe07384a911a6 100644 (file)
@@ -50,10 +50,18 @@ function get_sql_for_view_transactions($filtertype, $from, $to, &$trans_ref)
        elseif ($type_name != null)
                $sql .= " AND t.`$type_name` = ".db_escape($filtertype);
 
-       $sql .= " GROUP BY t.$type_name, t.$trans_no_name";
-       $sql .= " ORDER BY t.$trans_no_name";
+       // the ugly hack below is necessary to exclude old gl_trans records lasting after edition,
+       // otherwise old data transaction can be retrieved instead of current one.
+       if ($table_name==TB_PREF.'gl_trans')
+               $sql .= " AND t.`amount` <> 0";
 
+       $sql .= " GROUP BY ".($type_name ? "t.$type_name," : '')." t.$trans_no_name";
+       $sql .= " ORDER BY t.$trans_no_name";
        return $sql;
 }
 
+function transaction_exists($trans_type, $trans_no)
+{
+       return db_num_rows(db_query(get_sql_for_view_transactions($trans_type, $trans_no, $trans_no, $dummy)));
+}
 ?>
\ No newline at end of file