Fixes in sales reports to use debtor_trans.tax_included field instead of trans_tax_de...
[fa-stable.git] / gl / includes / db / gl_db_bank_trans.inc
index f393d5f901bf6ac958e1cbe17958c0f56a7906b0..59dbaa2322d178fa520dab093636449ef5f26f62 100644 (file)
@@ -87,11 +87,13 @@ function get_bank_trans_for_bank_account($bank_account, $from, $to)
 {
        $from = date2sql($from);
        $to = date2sql($to);
-       $sql = "SELECT ".TB_PREF."bank_trans.* FROM ".TB_PREF."bank_trans
-               WHERE ".TB_PREF."bank_trans.bank_act = ".db_escape($bank_account) . "
+       $sql = "SELECT t.* FROM "
+               .TB_PREF."bank_trans t LEFT JOIN ".TB_PREF."voided v ON t.type=v.type AND t.trans_no=v.id
+               WHERE t.bank_act = ".db_escape($bank_account) . "
+               AND ISNULL(v.date_)
                AND trans_date >= '$from'
                AND trans_date <= '$to'
-               ORDER BY trans_date,".TB_PREF."bank_trans.id";
+               ORDER BY trans_date, t.id";
 
        return db_query($sql,"The transactions for '" . $bank_account . "' could not be retrieved");
 }
@@ -153,7 +155,7 @@ function void_bank_trans($type, $type_no, $nested=false)
 
 /**
 *      Check account history to find transaction which would exceed authorized overdraft for given account.
-*      Returns null or transaction in conflict.
+*      Returns null or transaction in conflict. Running balance is checked on daily basis only, to enable ID change after edition.
 *      $delta_amount - tested change in bank balance at $date.
 **/
 function check_bank_account_history($delta_amount, $bank_account, $date, $user=null)
@@ -169,7 +171,8 @@ function check_bank_account_history($delta_amount, $bank_account, $date, $user=n
        $date = date2sql($date);
        $balance+= $delta_amount;
 
-       $sql = "SELECT * FROM ".TB_PREF."bank_trans WHERE bank_act=".db_escape($bank_account)." AND trans_date > '$date' ORDER BY trans_date ASC, id ASC";
+       $sql = "SELECT sum(amount) as amount FROM ".TB_PREF."bank_trans WHERE bank_act=".db_escape($bank_account)
+               ." AND trans_date >= '$date' GROUP BY trans_date ORDER BY trans_date ASC";
 
        $history = db_query($sql, "cannot retrieve cash account history");