Mysqli errors: Trying to access array offset on value of type bool. Fixed. Please...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 6 Jul 2021 07:19:44 +0000 (09:19 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 6 Jul 2021 07:19:44 +0000 (09:19 +0200)
27 files changed:
admin/db/tags_db.inc
fixed_assets/includes/fa_classes_db.inc
gl/bank_account_reconcile.php
gl/includes/db/gl_db_account_types.inc
gl/includes/db/gl_db_rates.inc
gl/includes/ui/gl_bank_ui.inc
includes/data_checks.inc
includes/db/crm_contacts_db.inc
includes/db/inventory_db.inc
includes/db_pager.inc
inventory/includes/db/items_category_db.inc
inventory/includes/db/items_units_db.inc
inventory/manage/sales_kits.php
purchasing/includes/db/suppliers_db.inc
reporting/rep306.php
reporting/rep307.php
reporting/rep308.php
reporting/rep310.php
reporting/rep451.php
sales/includes/db/cust_trans_db.inc
sales/includes/db/customers_db.inc
sales/includes/db/sales_delivery_db.inc
sales/includes/db/sales_groups_db.inc
sales/includes/db/sales_invoice_db.inc
sales/includes/db/sales_points_db.inc
sales/includes/db/sales_types_db.inc
taxes/db/tax_types_db.inc

index b33de8258fff244abfb98a8c478d4b4ebebbee29..40602a942b0c11183582bad6a006eb9a85868f64 100644 (file)
@@ -65,7 +65,7 @@ function get_tag_type($id)
        $result = db_query($sql, "could not get tag type");
 
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 //--------------------------------------------------------------------------------------
@@ -105,7 +105,7 @@ function get_tag_description($id)
        $result = db_query($sql, "could not get tag description");
 
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 //--------------------------------------------------------------------------------------
index 37fb5cebb082753cb18c81ada98940e8c03c71b4..8bbf8405870989a9548f893854fd8d1d1a41ab82 100644 (file)
@@ -27,7 +27,7 @@ function get_fixed_asset_classname($class)
 
        $row = db_fetch_row($result);
        
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 function update_fixed_asset_class($fa_class_id, $parent_id, $description, $long_description, $depreciation_rate)
index a5738946451ea7385e6890a128de1b3dd48d939b..6875e068e4b6e2d2949d7ff51e71da2f9b78b891 100644 (file)
@@ -175,7 +175,7 @@ if ($id != -1)
        change_tpl_flag($id);
 
 
-if (isset($_POST['Reconcile'])) {
+if (isset($_POST['last']) && isset($_POST['Reconcile'])) {
        set_focus('bank_date');
        foreach($_POST['last'] as $id => $value)
                if ($value != check_value('rec_'.$id))
@@ -184,7 +184,7 @@ if (isset($_POST['Reconcile'])) {
     $Ajax->activate('_page_body');
 }
 
-if (isset($_POST['ReconcileAll'])) {
+if (isset($_POST['last']) && isset($_POST['ReconcileAll'])) {
        set_focus('bank_date');
        foreach($_POST['last'] as $id => $value)
                set_tpl_flag($id);
index 4d6d58e876039aa5a7d29ee5fd82280f4323731f..04fd9e9980288f96fdf83a062424f5fb1686b6b7 100644 (file)
@@ -98,7 +98,7 @@ function get_account_type_name($id)
        $result = db_query($sql, "could not get account type");
 
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 function delete_account_type($id)
index 705c57d83acba0450e3801f22e6fef5d301713c7..525a6e2eea151696f44f61e2f28209021cb4715e 100644 (file)
@@ -32,7 +32,7 @@ function get_date_exchange_rate($curr_code, $date_)
        if(db_num_rows($result) == 0) 
                return 0;
        $row = db_fetch($result);
-               return $row[0];
+       return $row[0];
 }
 
 /*
index 34a4fed92971e618787409dde7e7ef11d0fe3c1a..a4a95b85a3027526bcd73d3964940e7f0273cb0b 100644 (file)
@@ -74,7 +74,7 @@ function display_bank_header(&$order)
                        hidden('PersonDetailID');
                }
                $trans = get_customer_habit($_POST['person_id']); // take care of customers on hold
-               if ($trans['dissallow_invoices'] != 0)
+               if (is_array($trans) && $trans['dissallow_invoices'] != 0)
                {
                        if ($payment)
                        {
@@ -230,14 +230,14 @@ function gl_edit_item_controls(&$order, $dim, $Index=null)
                        if ($_POST['PayType'] == PT_CUSTOMER)
                        {
                                $acc = get_branch_accounts($_POST['PersonDetailID']);
-                               $_POST['code_id'] = $acc['receivables_account'];
+                               $_POST['code_id'] = is_array($acc) ? $acc['receivables_account'] : '';
                        }
                        elseif ($_POST['PayType'] == PT_SUPPLIER)
                        {
                                $acc = get_supplier_accounts($_POST['person_id']);
-                               $_POST['code_id'] = $acc['payable_account'];
-                               $_POST['dimension_id'] = $acc['dimension_id'];
-                               $_POST['dimension2_id'] = $acc['dimension2_id'];
+                               $_POST['code_id'] = is_array($acc) ? $acc['payable_account'] : '';
+                               $_POST['dimension_id'] = is_array($acc) ? $acc['dimension_id'] : '';
+                               $_POST['dimension2_id'] = is_array($acc) ? $acc['dimension2_id'] : '';
                        }
                        else {
                                $_POST['code_id'] =
index 4b9689045e410c42e3140451a32bdc41cee30dd9..d6e5261a0066acfc569dbd3709ec086c2145c09b 100644 (file)
@@ -567,7 +567,7 @@ function check_empty_result($sql)
        $result = db_query($sql, "could not do check empty query");     
        
        $myrow = db_fetch_row($result);
-       return $myrow[0] > 0;
+       return is_array($myrow) ? $myrow[0] > 0 : false;
 }
 //
 //     Integer input check 
index e5a91fb1be4561bbca0c811b37074ab15ef63402..98862b73ae3c25d2a6ad338a34eef770e38850cb 100644 (file)
@@ -242,7 +242,7 @@ function get_crm_category_name($id)
        $result = db_query($sql, "could not get sales type");
 
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 //----------------------------------------------------------------------------------------
index 4ffda2e7abe2a1ff0497b71d7b2c691ab7e63766..9032e085726120b1789505453ed142f836e5faa0 100644 (file)
@@ -94,7 +94,7 @@ function get_item_edit_info($stock_id)
        $result = db_query($sql, "The standard cost cannot be retrieved");
 
        $row = db_fetch($result);
-       if ($row['decimals'] == -1)
+       if (is_array($row) && $row['decimals'] == -1)
                $row['decimals'] = user_qty_dec();
        return $row;
 }
@@ -110,7 +110,7 @@ function get_unit_cost($stock_id)
 
        $myrow = db_fetch_row($result);
 
-       return $myrow[0];
+       return is_array($myrow) ? $myrow[0] : false;
 }
 
 //--------------------------------------------------------------------------------------
@@ -124,7 +124,7 @@ function get_purchase_cost($stock_id)
 
        $myrow = db_fetch_row($result);
 
-       return $myrow[0];
+       return is_array($myrow) ? $myrow[0] : false;
 }
 
 //--------------------------------------------------------------------------------------
@@ -170,7 +170,7 @@ function get_already_delivered($stock_id, $location, $trans_no)
                AND type=".ST_CUSTDELIVERY." AND trans_no=".db_escape($trans_no);
        $result = db_query($sql, "Could not get stock moves");
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 /*
        Returns start move_id in latest negative status period for $stock_id
@@ -348,7 +348,7 @@ function get_purchase_value($stock_id)
 
        $result = db_query($sql,"retreive stock purchase price");
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 function update_purchase_value($stock_id, $price)
index affb9e09796e9cf046abdb0998817ed533eac076..e3f3b167ad777ccdf87d77dd12d4092fdeb5a95f 100644 (file)
@@ -349,7 +349,8 @@ class db_pager {
                        if ($result == false) 
                                return false;
                        $row = db_fetch_row($result);
-                       $this->rec_count = $row[0];
+                       $this->rec_count = is_array($row) ? $row[0] : 0;
+;
                        $this->max_page = $this->page_len ?
                                ceil($this->rec_count/$this->page_len) : 0;
                
index 8b6d872aefaec0eb1bd5a9d442ae5c6fcccf3d38..2c79d1373f1b45499bf774c917544572c76340ca 100644 (file)
@@ -98,6 +98,6 @@ function get_category_name($id)
        $result = db_query($sql, "could not get sales type");
 
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
index d90b03b39e18944493aa4819da6826d756e49cb2..486db56219e16311b0847684520ae1e092f470be 100644 (file)
@@ -48,7 +48,7 @@ function get_unit_descr($unit)
        $result = db_query($sql, "could not retrieve unit description");
 
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 function item_unit_used($unit) {
@@ -72,6 +72,6 @@ function get_unit_dec($stock_id)
        $result = db_query($sql, "could not get unit decimals");
 
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
index c8a80687dfc098d7eb6077d4b75301cedde2548a..849564dd75c32792a44e53862c10867e29e31d84 100644 (file)
@@ -224,8 +224,8 @@ if (get_post('item_code') == '') {
 
        if (get_post('item_code') == '') { // new kit/alias
                if ($Mode!='ADD_ITEM' && $Mode!='UPDATE_ITEM') {
-                       $_POST['description'] = $props['description'];
-                       $_POST['category'] = $props['category_id'];
+                       $_POST['description'] = is_array($props) ? $props['description'] : '';
+                       $_POST['category'] = is_array($props) ? $props['category_id'] : '';
                }
                text_row(_("Description:"), 'description', null, 50, 200);
                stock_categories_list_row(_("Category:"), 'category', null);
index 602b86bf60049a52f50d3c385785510480909acb..dff68c123c302e1a7bdf6700b577dfd9425e7a5e 100644 (file)
@@ -144,7 +144,7 @@ function get_supplier_name($supplier_id)
 
        $row = db_fetch_row($result);
 
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 function get_supplier_accounts($supplier_id)
index 3ce3a86025bd49314d54a4d5a60f706e7f390300..9dc886a10bea22481318af64bae8e8ac0e9f1ae6 100644 (file)
@@ -85,10 +85,7 @@ function get_supp_inv_reference($supplier_id, $stock_id, $date)
                AND trans.tran_date=".db_escape($date);
     $result = db_query($sql,"No transactions were returned");
     $row = db_fetch_row($result);
-    if (isset($row[0]))
-       return $row[0];
-    else
-       return '';
+       return is_array($row) ? $row[0] : '';
 }
 
 //----------------------------------------------------------------------------------------------------
index 18cfc6ea064852c614116de5700e5d9038f79164..d9d9c29e29d27b464c30e853d27ef87234b87089 100644 (file)
@@ -45,7 +45,7 @@ function fetch_items($category=0)
     return db_query($sql,"No transactions were returned");
 }
 
-function trans_qty($stock_id, $location=null, $from_date, $to_date, $inward = true)
+function trans_qty($stock_id, $location, $from_date, $to_date, $inward = true)
 {
        if ($from_date == null)
                $from_date = Today();
index 0981c2ad64276153b9e67943192ad18a9e34547a..ffd880ebc804b86c2b34c04cc5f2c21f3df83793 100644 (file)
@@ -64,7 +64,7 @@ function fetch_items($category=0)
     return db_query($sql,"No transactions were returned");
 }
 
-function trans_qty($stock_id, $location=null, $from_date, $to_date, $inward = true)
+function trans_qty($stock_id, $location, $from_date, $to_date, $inward = true)
 {
        if ($from_date == null)
                $from_date = Today();
@@ -97,7 +97,7 @@ function trans_qty($stock_id, $location=null, $from_date, $to_date, $inward = tr
 
 }
 
-function avg_unit_cost($stock_id, $location=null, $to_date)
+function avg_unit_cost($stock_id, $location, $to_date)
 {
        if ($to_date == null)
                $to_date = Today();
@@ -139,7 +139,7 @@ function avg_unit_cost($stock_id, $location=null, $to_date)
 
 //----------------------------------------------------------------------------------------------------
 
-function trans_qty_unit_cost($stock_id, $location=null, $from_date, $to_date, $inward = true)
+function trans_qty_unit_cost($stock_id, $location, $from_date, $to_date, $inward = true)
 {
        if ($from_date == null)
                $from_date = Today();
index ff17aa27e1a83aaf1496d02040d20c9ff1f4a6ab..54de32e84b6047344e8734994d890f87291a1fb8 100644 (file)
@@ -86,10 +86,7 @@ function get_supp_inv_reference($supplier_id, $stock_id, $date)
                AND trans.tran_date=".db_escape($date);
     $result = db_query($sql,"No transactions were returned");
     $row = db_fetch_row($result);
-    if (isset($row[0]))
-       return $row[0];
-    else
-       return '';
+       return is_array($row) ? $row[0] : '';
 }
 
 //----------------------------------------------------------------------------------------------------
index ece0519b7af61ec3df4d7ea896b504483368736e..28bdae6a7182b6e44a51b2cae074e156df92c2a2 100644 (file)
@@ -33,7 +33,7 @@ function find_last_location($stock_id, $end_date)
                tran_date <= '$end_date' ORDER BY tran_date DESC LIMIT 1";
        $res = db_query($sql,"No stock moves were returned");
        $row = db_fetch_row($res);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 //----------------------------------------------------------------------------------------------------
index 401c7a54580388285b35672c13e16e077e166ed7..a68063b8ff8f0cc315c0ddd09911e79b8c5bced5 100644 (file)
@@ -244,7 +244,7 @@ function get_customer_trans_order($type, $type_no)
 
        $row = db_fetch_row($result);
 
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 //----------------------------------------------------------------------------------------
index f9b111a0b70445160b0ec3612f357576d664bfec..3f16159e46ddc434fe45048405ca60005e89fab7 100644 (file)
@@ -132,7 +132,7 @@ function get_customer_name($customer_id)
 
        $row = db_fetch_row($result);
 
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 function get_customer_habit($customer_id)
@@ -165,6 +165,8 @@ function get_current_cust_credit($customer_id)
 {
        $custdet = get_customer_details($customer_id);
 
+       if (!is_array($custdet))
+               return 0;
        return $custdet['credit_limit']-$custdet['Balance'];
 
 }
index 9f0ecbca9c11675234348171c88d3e9a336b5d6b..ebb04860299d45042031b5e2ba1eee61f06efe8e 100644 (file)
@@ -210,7 +210,7 @@ function adjust_shipping_charge(&$delivery, $trans_no)
        $sql = "SELECT sum(ov_freight) as freight FROM ".TB_PREF."debtor_trans WHERE order_ = $trans_no AND type = " . ST_CUSTDELIVERY . " AND debtor_no = " . $delivery->customer_id;
        $result = db_query($sql, "Can not find delivery notes");
        $row = db_fetch_row($result);
-       if (!$row[0]) $freight = 0;
+       if (!is_array($row)) $freight = 0;
        else $freight = $row[0];
        if ($freight < $delivery->freight_cost) $delivery->freight_cost = $delivery->freight_cost - $freight;
        else $delivery->freight_cost = 0;
index f68a3bb6ec95d33693a0299d06dc00072d18adae..6f926d7ee7887d1e3f5eaa091a8d796be8470646 100644 (file)
@@ -49,7 +49,7 @@ function get_sales_group_name($group_no)
        $sql = "SELECT description FROM ".TB_PREF."groups WHERE id = ".db_escape($group_no);
        $result = db_query($sql, "could not get group");
        $row = db_fetch($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 function add_sales_area($description)
@@ -92,7 +92,7 @@ function get_area_name($id)
        $result = db_query($sql, "could not get sales type");
 
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 function add_salesman($salesman_name, $salesman_phone, $salesman_fax,
@@ -151,7 +151,7 @@ function get_salesman_name($id)
        $result = db_query($sql, "could not get sales type");
 
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 
index c17e9214e361e936664bbdf93a68c736765d4edc..b1cbfa3f8209fbc5cfde929b3a13274c7c18d447 100644 (file)
@@ -291,7 +291,7 @@ function get_cust_prepayment_invoice_factor($trans_no)
                LEFT JOIN ".TB_PREF."sales_orders so ON so.trans_type=".ST_SALESORDER." AND so.order_no=dt.order_
                 WHERE dt.type=".ST_SALESINVOICE." AND trans_no=".db_escape($trans_no);
        $row = db_fetch(db_query($sql, 'cannot retrieve prepaid invoice factor'));
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 /*
index b5abaef7f7f631bb1775bdaa5f9e42bf6b6b3679..9537a913812e95b6abefaf21a738e2a5767bf94f 100644 (file)
@@ -61,7 +61,7 @@ function get_sales_point_name($id)
        $result = db_query($sql, "could not get POS name");
        
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 function delete_sales_point($id)
index a0279d3e5045f0947e71d9a5c3bd7e33f174793d..6007eb257d1655e10280c1fd152e203ce7e88483 100644 (file)
@@ -50,7 +50,7 @@ function get_sales_type_name($id)
        $result = db_query($sql, "could not get sales type");
        
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 function delete_sales_type($id)
index ce73935f61b95c17756865ac824b3ebf605b211c..b927bb05ce0a6a5ebc21b5a20bb55c4faea1ef2f 100644 (file)
@@ -73,7 +73,7 @@ function get_tax_type_rate($type_id)
        $result = db_query($sql, "could not get tax type rate");
 
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 function delete_tax_type($type_id)