{
$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");
}
/**
* 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)
$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");