Wrong column for array_substitute in delivery and invoice templates.
[fa-stable.git] / purchasing / includes / db / suppliers_db.inc
index 17bd33f2e46765cb4d3ee65e0857c34b50d0db00..dd9e49c906fa3cbb4689ba5e95e2387d368555e3 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)
-               VALUES (".db_escape($_POST['supp_name']). ", "
+               VALUES (".db_escape($supp_name). ", "
                .db_escape($supp_ref). ", "
                .db_escape($address) . ", "
                .db_escape($supp_address) . ", "
@@ -27,7 +27,7 @@ function add_supplier($supp_name, $supp_ref, $address, $supp_address, $gst_no,
                .db_escape($website). ", "
                .db_escape($supp_account_no). ", "
                .db_escape($bank_account). ", "
-               .$credit_limit. ", "
+               .db_escape($credit_limit). ", "
                .db_escape($dimension_id). ", "
                .db_escape($dimension2_id). ", "
                .db_escape($curr_code). ", "
@@ -88,7 +88,12 @@ function get_supplier_details($supplier_id, $to=null, $all=true)
        $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,7 +114,7 @@ function get_supplier_details($supplier_id, $to=null, $all=true)
                         supp.payment_terms = ".TB_PREF."payment_terms.terms_indicator
                         AND supp.supplier_id = $supplier_id ";
        if (!$all)
-               $sql .= "AND ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount - trans.alloc) > 0.004 ";  
+               $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,