Paged transaction inquiries optimized for maximum links in Sales and Purchasing.
[fa-stable.git] / purchasing / includes / db / po_db.inc
index a82eb9a584649c0b0d90f35441b1d09eacd40b27..a904c2ff4b396cf47135975c05b31b6362a7dd61 100644 (file)
@@ -14,8 +14,7 @@
 function get_supplier_details_to_order(&$order, $supplier_id)
 {
        $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included, dimension_id, dimension2_id,
-                       supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1) 
-                               * (ov_amount + ov_gst + ov_discount),0)) as cur_credit,
+                       supp.credit_limit - Sum((ov_amount + ov_gst + ov_discount)) as cur_credit,
                                terms.terms, terms.days_before_due, terms.day_in_following_month
                FROM ".TB_PREF."suppliers supp
                         LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id
@@ -295,6 +294,8 @@ function get_sql_for_po_search_completed($from, $to, $supplier_id=ALL_TEXT, $loc
                porder.ord_date, 
                supplier.curr_code, 
                Sum(line.unit_price*line.quantity_ordered) AS OrderValue,
+               Sum(line.delivery_date < '". date2sql(Today()) ."'
+               AND (line.quantity_ordered > line.quantity_received)) As OverDue,
                porder.into_stock_location,
                chk.isopen
                FROM ".TB_PREF."purch_orders as porder