Error: no supplier trans found for given params in Supplier Payment. Fixed.
[fa-stable.git] / purchasing / includes / db / po_db.inc
index a82eb9a584649c0b0d90f35441b1d09eacd40b27..23f19a09f582b81b56c8b63ca2df6244ac19a60c 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
@@ -50,7 +49,7 @@ function delete_po($po)
        global $Refs;
 
        begin_transaction();
-       hook_db_prevoid($po, ST_PURCHORDER);
+       hook_db_prevoid(ST_PURCHORDER, $po);
        $sql = "DELETE FROM ".TB_PREF."purch_orders WHERE order_no=".db_escape($po);
        db_query($sql, "The order header could not be deleted");
 
@@ -161,6 +160,15 @@ function update_po(&$po_obj)
 
 //----------------------------------------------------------------------------------------
 
+function get_po($order_no) {
+    $sql = "SELECT * FROM ".TB_PREF."purch_orders WHERE order_no = ".db_escape($order_no);
+    $result = db_query($sql);
+
+    return db_fetch($result);
+}
+
+//----------------------------------------------------------------------------------------
+
 function read_po_header($order_no, &$order)
 {
        $sql = "SELECT po.*, supplier.*, loc.location_name 
@@ -295,6 +303,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