X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=gl%2Fincludes%2Fdb%2Fgl_db_bank_trans.inc;h=e8d8190552051b7b6bf51e698245de56f014cb72;hb=4deaa6ba6e084655989c30cfb7d9dd307408c7dc;hp=e0dbdf287f21ac8f374e6afc9b3c8024cf86e7f8;hpb=f44132511cc91b83f20f91af0625d4b112b4c26e;p=fa-stable.git diff --git a/gl/includes/db/gl_db_bank_trans.inc b/gl/includes/db/gl_db_bank_trans.inc index e0dbdf28..e8d81905 100644 --- a/gl/includes/db/gl_db_bank_trans.inc +++ b/gl/includes/db/gl_db_bank_trans.inc @@ -16,7 +16,7 @@ // $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_); @@ -34,9 +34,6 @@ function add_bank_trans($type, $trans_no, $bank_act, $ref, $date_, $amount_bank = $amount; $amount_bank = round2($amount_bank, user_price_dec()); - // Also store the rate to the home - //$BankToHomeCurrencyRate = get_exchange_rate_to_home_currency($bank_account_currency, $date_); - $sql = "INSERT INTO ".TB_PREF."bank_trans (type, trans_no, bank_act, ref, trans_date, amount, person_type_id, person_id) "; @@ -44,10 +41,7 @@ function add_bank_trans($type, $trans_no, $bank_act, $ref, $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"); } //---------------------------------------------------------------------------------------- @@ -79,13 +73,13 @@ function get_bank_trans($type, $trans_no=null, $person_type_id=null, $person_id= 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"; @@ -146,13 +140,13 @@ function void_bank_trans($type, $type_no, $nested=false) { if (!$nested) - begin_transaction(); + begin_transaction(__FUNCTION__, func_get_args()); $sql = "UPDATE ".TB_PREF."bank_trans SET amount=0 WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no); - $result = db_query($sql, "could not void bank transactions for type=$type and trans_no=$type_no"); + db_query($sql, "could not void bank transactions for type=$type and trans_no=$type_no"); void_gl_trans($type, $type_no, true); @@ -175,22 +169,23 @@ function void_bank_trans($type, $type_no, $nested=false) * 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=null, $user=null) +function check_bank_account_history($delta_amount, $bank_account, $date=null, $user=null, $balance_offset = 0) { if ($delta_amount >= 0 && isset($date)) - return null; // amount increese is always safe + return null; // amount increase is always safe $balance = $date ? get_bank_account_limit($bank_account, $date, $user) : 0; if (!isset($balance) && isset($date)) return null; // unlimited account + $balance += $balance_offset; if (floatcmp($balance, -$delta_amount) < 0) return array('amount' => $balance + $delta_amount, 'trans_date'=> date2sql($date)); $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) @@ -204,7 +199,7 @@ function check_bank_account_history($delta_amount, $bank_account, $date=null, $u while ($trans = db_fetch($history)) { $balance += $trans['amount']; - if ($balance < 0) + if (round2($balance, user_price_dec()) < 0) { $trans['amount'] = $balance; return $trans; @@ -228,3 +223,10 @@ function check_void_bank_trans($type, $type_no) 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"); +}