Error calculating customer aging regarding journal entries. Fixed.
[fa-stable.git] / sales / includes / db / customers_db.inc
index 675e1b736c6e589cce25403e049e9bc72586e769..8d4239189443652a07e66c748b6929f4e2072f00 100644 (file)
@@ -55,7 +55,7 @@ function delete_customer($customer_id)
        begin_transaction();
        delete_entity_contacts('customer', $customer_id);
 
-       $sql = "DELETE FROM ".TB_PREF."debtors_master WHERE debtor_no=".db_escape($customer_id);;
+       $sql = "DELETE FROM ".TB_PREF."debtors_master WHERE debtor_no=".db_escape($customer_id);
        db_query($sql,"cannot delete customer");
        commit_transaction();
 }
@@ -97,7 +97,7 @@ function get_customer_details($customer_id, $to=null, $all=true)
                $sql .= " AND debtor.debtor_no = ".db_escape($customer_id);
 
        if (!$all)
-               $sql .= " AND ABS(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount - trans.alloc) > ".FLOAT_COMP_DELTA;
+               $sql .= " AND ABS(trans.ov_amount) + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount - trans.alloc > ".FLOAT_COMP_DELTA;
        $sql .= " GROUP BY
                                debtor.name,
                                terms.terms,
@@ -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'];
 
 }
@@ -197,7 +199,7 @@ function get_customer_currency($customer_id=null, $branch_id=null)
        $result = db_query($sql, "Retreive currency of customer $customer_id");
 
        $myrow=db_fetch_row($result);
-       return $myrow[0];
+       return $myrow ? $myrow[0] : get_company_currency();
 }
 
 function get_customers_search($customer)