Stable merged into unstable again (due to failure on binary file during previous...
[fa-stable.git] / purchasing / includes / db / suppliers_db.inc
index 04228e9d5a721dd5fc5a12fc22421d0662fb6cee..61cf2bdce8a8194ab8e4bdda72024cbffa38679d 100644 (file)
@@ -79,7 +79,7 @@ function delete_supplier($supplier_id)
        db_query($sql,"check failed");
 }
 
-function get_supplier_details($supplier_id, $to=null)
+function get_supplier_details($supplier_id, $to=null, $all=true)
 {
 
        if ($to == null)
@@ -90,7 +90,12 @@ function get_supplier_details($supplier_id, $to=null)
        $past2 = 2 * $past1;
        // removed - supp_trans.alloc from all summations
 
-    $value = "(trans.ov_amount + trans.ov_gst + trans.ov_discount)";
+       if ($all)
+       $value = "(trans.ov_amount + trans.ov_gst + trans.ov_discount)";
+    else       
+       $value = "IF (trans.type=".ST_SUPPINVOICE." OR trans.type=".ST_BANKDEPOSIT.",
+               (trans.ov_amount + trans.ov_gst + trans.ov_discount - trans.alloc),
+               (trans.ov_amount + trans.ov_gst + trans.ov_discount + trans.alloc))";
        $due = "IF (trans.type=".ST_SUPPINVOICE." OR trans.type=".ST_SUPPCREDIT.",trans.due_date,trans.tran_date)";
     $sql = "SELECT supp.supp_name, supp.curr_code, ".TB_PREF."payment_terms.terms,
 
@@ -109,15 +114,15 @@ function get_supplier_details($supplier_id, $to=null)
 
                WHERE
                         supp.payment_terms = ".TB_PREF."payment_terms.terms_indicator
-                        AND supp.supplier_id = $supplier_id
-
-               GROUP BY
+                        AND supp.supplier_id = $supplier_id ";
+       if (!$all)
+               $sql .= "AND ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount) - trans.alloc > ".FLOAT_COMP_DELTA." ";  
+       $sql .= "GROUP BY
                          supp.supp_name,
                          ".TB_PREF."payment_terms.terms,
                          ".TB_PREF."payment_terms.days_before_due,
                          ".TB_PREF."payment_terms.day_in_following_month";
-
-    $result = db_query($sql,"The supplier details could not be retrieved");
+    $result = db_query($sql,"The customer details could not be retrieved");
     $supp = db_fetch($result);
 
     return $supp;
@@ -182,5 +187,3 @@ function update_supp_tax_algorithm($supplier_id, $tax_algorithm)
                . " WHERE supplier_id=".db_escape($supplier_id);
        return db_query($sql, "cannot update supplier's tax calculation algorithm");
 }
-
-?>
\ No newline at end of file