Report Aged Supplier Analysis, Show Also Allocated = No. SQL Problem fixed.
[fa-stable.git] / purchasing / includes / db / suppliers_db.inc
index 733f5b159b44e85a533abd245fa02dcabd893a0a..d66c89fc7941fb20c3912d1175eb0413b366fb2a 100644 (file)
@@ -92,9 +92,9 @@ function get_supplier_details($supplier_id, $to=null, $all=true)
        $value = "(trans.ov_amount + trans.ov_gst + trans.ov_discount)";
     else       
        $value = "IF (trans.type=".ST_SUPPINVOICE." OR trans.type=".ST_BANKDEPOSIT."
-       OR (trans.type=".ST_JOURNAL." AND (trans.ov_amount + trans.ov_gst + trans.ov_discount)>0),
-               (trans.ov_amount + trans.ov_gst + trans.ov_discount - trans.alloc),
-               (trans.ov_amount + trans.ov_gst + trans.ov_discount + trans.alloc))";
+       OR (trans.type=".ST_JOURNAL." AND (trans.ov_amount + trans.ov_gst + trans.ov_discount)>0), 1, -1)*
+               ABS(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,
 
@@ -149,7 +149,7 @@ function get_supplier_name($supplier_id)
 
 function get_supplier_accounts($supplier_id)
 {
-       $sql = "SELECT payable_account,purchase_account,payment_discount_account FROM ".TB_PREF."suppliers WHERE supplier_id=".db_escape($supplier_id);
+       $sql = "SELECT payable_account,purchase_account,payment_discount_account, dimension_id, dimension2_id FROM ".TB_PREF."suppliers WHERE supplier_id=".db_escape($supplier_id);
 
        $result = db_query($sql, "could not get supplier");
 
@@ -190,3 +190,23 @@ function get_supplier_currency($supplier_id)
        return $myrow[0];
 }
 
+function get_suppliers_search($supplier)
+{
+       global $SysPrefs;
+
+       if (isset($SysPrefs->max_rows_in_search))
+               $limit = $SysPrefs->max_rows_in_search;
+       else
+               $limit = 10;
+
+       $sql = "SELECT supplier_id, supp_name, supp_ref, address, gst_no
+               FROM ".TB_PREF."suppliers
+               WHERE (supp_name LIKE " . db_escape("%" . $supplier. "%") . " OR 
+                       supp_ref LIKE " . db_escape("%" . $supplier. "%") . " OR 
+                       address LIKE " . db_escape("%" . $supplier. "%") . " OR 
+                       gst_no LIKE " . db_escape("%" . $supplier. "%") . ")
+               ORDER BY supp_name LIMIT 0,".(int)($limit);
+
+       return db_query($sql, "Failed in retreiving supplier list.");
+}
+