Fixed warnings related to empty item/customer/supplier selector in search modes.
[fa-stable.git] / gl / includes / db / gl_db_bank_accounts.inc
index ef6793e25fd955783928ef20958e5d6b7c1fae2d..ee535be7b1eb75302ada063dfc76931d3f89a305 100644 (file)
@@ -1,12 +1,12 @@
 <?php
 /**********************************************************************
     Copyright (C) FrontAccounting, LLC.
-       Released under the terms of the GNU General Public License, GPL, 
-       as published by the Free Software Foundation, either version 3 
+       Released under the terms of the GNU General Public License, GPL,
+       as published by the Free Software Foundation, either version 3
        of the License, or (at your option) any later version.
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
 //---------------------------------------------------------------------------------------------
@@ -78,8 +78,8 @@ function get_bank_account($id)
 
 function get_bank_accounts($show_inactive=false)
 {
-       $sql = "SELECT account.*, gl_account.account_name 
-               FROM ".TB_PREF."bank_accounts account, ".TB_PREF."chart_master gl_account 
+       $sql = "SELECT account.*, gl_account.account_name
+               FROM ".TB_PREF."bank_accounts account, ".TB_PREF."chart_master gl_account
                WHERE account.account_code = gl_account.account_code";
        if (!$show_inactive) $sql .= " AND !account.inactive";
        $sql .= " ORDER BY account_code, bank_curr_code";
@@ -209,17 +209,14 @@ function get_quick_entry($selected_id)
        $result = db_query($sql, "could not retreive quick entry $selected_id");
 
        return db_fetch($result);
-}      
+}
 
 function get_quick_entry_lines($qid)
 {
-       $sql = "SELECT ".TB_PREF."quick_entry_lines.*, ".TB_PREF."chart_master.account_name,
-                       ".TB_PREF."tax_types.name as tax_name
-               FROM ".TB_PREF."quick_entry_lines
-               LEFT JOIN ".TB_PREF."chart_master ON
-                       ".TB_PREF."quick_entry_lines.dest_id = ".TB_PREF."chart_master.account_code
-               LEFT JOIN ".TB_PREF."tax_types ON
-                       ".TB_PREF."quick_entry_lines.dest_id = ".TB_PREF."tax_types.id
+       $sql = "SELECT line.*, coa.account_name, taxtype.name as tax_name
+               FROM ".TB_PREF."quick_entry_lines line
+                       LEFT JOIN ".TB_PREF."chart_master coa ON line.dest_id = coa.account_code
+                       LEFT JOIN ".TB_PREF."tax_types taxtype ON line.dest_id = taxtype.id
                WHERE 
                        qid=".db_escape($qid)." ORDER by id";
 
@@ -280,13 +277,15 @@ function get_ending_reconciled($bank_account, $bank_date)
 
 function get_sql_for_bank_account_reconcile($bank_account, $date)
 {
-       $sql = "SELECT  type, trans_no, ref, trans_date, 
-                               amount, person_id, person_type_id, reconciled, id
-               FROM ".TB_PREF."bank_trans
-               WHERE ".TB_PREF."bank_trans.bank_act = ".db_escape($bank_account) . "
+       $sql = "SELECT  bt.type, trans_no, ref, trans_date,
+                               amount, person_id, person_type_id, reconciled, bt.id, c.memo_
+               FROM ".TB_PREF."bank_trans bt
+               LEFT JOIN ".TB_PREF."comments c ON c.type = bt.type AND c.id = bt.trans_no
+               WHERE bank_act = ".db_escape($bank_account) . "
                        AND (reconciled IS NULL OR reconciled='". date2sql($date) ."')
-               ORDER BY trans_date,".TB_PREF."bank_trans.id";
-// or  ORDER BY reconciled desc, trans_date,".TB_PREF."bank_trans.id";
+                       AND amount != 0
+               ORDER BY trans_date, bt.id";
+
        return $sql;
 }
 
@@ -345,8 +344,8 @@ function get_default_supplier_bank_account($supplier_id)
        $sql = "SELECT curr_code FROM ".TB_PREF."suppliers WHERE supplier_id=".db_escape($supplier_id);
        $result = db_query($sql, "could not retreive default supplier currency code");
        $row = db_fetch_row($result);
-       $ba = get_default_bank_account($row[0]);
-       return $ba['id'];
+       $id = $row ? get_default_bank_account($row[0])['id'] : 0;
+       return $id;
 }
 //---------------------------------------------------------------------------------------------
 //