Error: no supplier trans found for given params in Supplier Payment. Fixed.
[fa-stable.git] / purchasing / includes / db / po_db.inc
index fbc3a8cc984987c496ea701ab153815266755063..23f19a09f582b81b56c8b63ca2df6244ac19a60c 100644 (file)
@@ -13,9 +13,8 @@
 
 function get_supplier_details_to_order(&$order, $supplier_id)
 {
-       $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included,
-                       supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1) 
-                               * (ov_amount + ov_gst + ov_discount),0)) as cur_credit,
+       $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included, dimension_id, dimension2_id,
+                       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
@@ -36,6 +35,8 @@ function get_supplier_details_to_order(&$order, $supplier_id)
        $_POST['supplier_id'] = $supplier_id;
        $_POST['supplier_name'] = $myrow["supp_name"];
        $_POST['curr_code'] = $myrow["curr_code"];
+       $_POST['dimension'] = $myrow["dimension_id"];
+       $_POST['dimension2'] = $myrow["dimension2_id"];
 
        $order->set_supplier($supplier_id, $myrow["supp_name"], $myrow["curr_code"], 
                $myrow["tax_group_id"], $myrow["tax_included"]);
@@ -48,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");
 
@@ -148,7 +149,7 @@ function update_po(&$po_obj)
                db_query($sql, "One of the purchase order detail records could not be updated");
     }
 
-       reallocate_payments($po_obj->order_no, ST_PURCHORDER, $po_obj->orig_order_date, $po_obj->get_trans_total(), $po_obj->prepayments);
+       reallocate_payments($po_obj->order_no, ST_PURCHORDER, $po_obj->orig_order_date, $po_obj->get_trans_total(), $po_obj->prepayments, $po_obj->supplier_id);
 
        add_audit_trail($po_obj->trans_type, $po_obj->order_no, Today(), _("Updated."));
        hook_db_postwrite($po_obj, ST_PURCHORDER);
@@ -159,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 
@@ -185,14 +195,14 @@ function read_po_header($order_no, &$order)
                $order->credit = get_current_supp_credit($order->supplier_id);
 
        $order->orig_order_date = sql2date($myrow["ord_date"]);
-       $order->Comments = nl2br($myrow["comments"]);
+       $order->Comments = $myrow["comments"];
        $order->Location = $myrow["into_stock_location"];
        $order->supp_ref = $myrow["requisition_no"];
        $order->reference = $myrow["reference"];
        $order->delivery_address = $myrow["delivery_address"];
        $order->alloc = $myrow["alloc"];
        $order->prep_amount = $myrow["prep_amount"];
-       $order->prepayments = get_payments_for($order_no, ST_PURCHORDER);
+       $order->prepayments = get_payments_for($order_no, ST_PURCHORDER, $myrow["supplier_id"]);
 
        return true;
        }
@@ -293,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