// $date_ is display date (non-sql)
function add_bank_trans($type, $trans_no, $bank_act, $ref, $date_,
- $amount, $person_type_id, $person_id, $currency="", $err_msg="", $rate=0)
+ $amount, $person_type_id, $person_id, $currency="", $rate=0)
{
$sqlDate = date2sql($date_);
".db_escape($amount_bank).", ".db_escape($person_type_id)
.", ". db_escape($person_id).")";
- if ($err_msg == "")
- $err_msg = "The bank transaction could not be inserted";
-
- db_query($sql, $err_msg);
+ db_query($sql, "The bank transaction could not be inserted");
}
//----------------------------------------------------------------------------------------
LEFT JOIN ".TB_PREF."suppliers supplier ON supplier.supplier_id = st.supplier_id,
".TB_PREF."bank_accounts act
WHERE act.id=bt.bank_act ";
- if ($type != null)
+ if (isset($type))
$sql .= " AND bt.type=".db_escape($type);
- if ($trans_no != null)
+ if (isset($trans_no))
$sql .= " AND bt.trans_no = ".db_escape($trans_no);
- if ($person_type_id != null)
+ if (isset($person_type_id))
$sql .= " AND bt.person_type_id = ".db_escape($person_type_id);
- if ($person_id != null)
+ if (isset($person_id))
$sql .= " AND bt.person_id = ".db_escape($person_id);
$sql .= " ORDER BY trans_date, bt.id";
{
if (!$nested)
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
$sql = "UPDATE ".TB_PREF."bank_trans
SET amount=0
$balance += $delta_amount;
- $sql = "SELECT sum(amount) as amount, trans_date
+ $sql = "SELECT sum(amount) as amount, trans_date, trans_no, type
FROM ".TB_PREF."bank_trans
WHERE bank_act=".db_escape($bank_account);
if ($date)
while ($trans = db_fetch($history)) {
$balance += $trans['amount'];
- if ($balance < 0)
+ if (round2($balance, user_price_dec()) < 0)
{
$trans['amount'] = $balance;
return $trans;
return true;
}
+function update_reconcile_date($type, $trans_no, $date=NULL)
+{
+ $sql = "UPDATE ".TB_PREF."bank_trans SET reconciled=".($date ? "'".date2sql($date)."'" : 'NULL')
+ ." WHERE type=" . db_escape($type). " AND trans_no=".db_escape($trans_no);
+
+ db_query($sql, "Can't change reconciliation status");
+}