Fixed include file issue in sales order entry.
[fa-stable.git] / purchasing / includes / db / suppliers_db.inc
index 04228e9d5a721dd5fc5a12fc22421d0662fb6cee..6b7d0cde787265665cfc21c5a188a0bf6f5f0f43 100644 (file)
@@ -19,7 +19,7 @@ function add_supplier($supp_name, $supp_ref, $address, $supp_address, $gst_no,
                supp_account_no, bank_account, credit_limit, dimension_id, dimension2_id, curr_code,
                payment_terms, payable_account, purchase_account, payment_discount_account, notes, 
                tax_group_id, tax_included, tax_algorithm)
-               VALUES (".db_escape($_POST['supp_name']). ", "
+               VALUES (".db_escape($supp_name). ", "
                .db_escape($supp_ref). ", "
                .db_escape($address) . ", "
                .db_escape($supp_address) . ", "
@@ -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;
@@ -183,4 +188,13 @@ function update_supp_tax_algorithm($supplier_id, $tax_algorithm)
        return db_query($sql, "cannot update supplier's tax calculation algorithm");
 }
 
-?>
\ No newline at end of file
+function get_supplier_currency($supplier_id)
+{
+    $sql = "SELECT curr_code FROM ".TB_PREF."suppliers WHERE supplier_id = ".db_escape($supplier_id);
+
+       $result = db_query($sql, "Retreive currency of supplier $supplier_id");
+
+       $myrow=db_fetch_row($result);
+       return $myrow[0];
+}
+