Stable merged into unstable again (due to failure on binary file during previous...
[fa-stable.git] / purchasing / includes / db / po_db.inc
index 859deaa78cc877e551e1df868b0f992726d7443b..45810f1da0b9050b430457a06aaf3f0d64cb0370 100644 (file)
@@ -13,6 +13,7 @@
 
 function delete_po($po)
 {
+       hook_db_prevoid($po, ST_PURCHORDER);
        $sql = "DELETE FROM ".TB_PREF."purch_orders WHERE order_no=".db_escape($po);
        db_query($sql, "The order header could not be deleted");
 
@@ -27,6 +28,7 @@ function add_po(&$po_obj)
        global $Refs;
 
        begin_transaction();
+       hook_db_prewrite($po_obj, ST_PURCHORDER);
 
      /*Insert to purchase order header record */
      $sql = "INSERT INTO ".TB_PREF."purch_orders (supplier_id, Comments, ord_date, reference, 
@@ -64,6 +66,7 @@ function add_po(&$po_obj)
        //add_comments(ST_PURCHORDER, $po_obj->order_no, $po_obj->orig_order_date, $po_obj->Comments);
 
        add_audit_trail(ST_PURCHORDER, $po_obj->order_no, $po_obj->orig_order_date);
+       hook_db_postwrite($po_obj, ST_PURCHORDER);
        commit_transaction();
 
        return $po_obj->order_no;
@@ -74,6 +77,7 @@ function add_po(&$po_obj)
 function update_po(&$po_obj)
 {
        begin_transaction();
+       hook_db_prewrite($po_obj, ST_PURCHORDER);
 
     /*Update the purchase order header with any changes */
     $sql = "UPDATE ".TB_PREF."purch_orders SET Comments=" . db_escape($po_obj->Comments) . ",
@@ -94,21 +98,22 @@ function update_po(&$po_obj)
     foreach ($po_obj->line_items as $po_line)
     {
        $sql = "INSERT INTO ".TB_PREF."purch_order_details (po_detail_item, order_no, item_code, 
-               description, delivery_date, unit_price, quantity_ordered) VALUES ("
+               description, delivery_date, unit_price, quantity_ordered, quantity_received) VALUES ("
                        .db_escape($po_line->po_detail_rec ? $po_line->po_detail_rec : 0). ","
                        .$po_obj->order_no . ","
                        .db_escape($po_line->stock_id). ","
                        .db_escape($po_line->item_description). ",'"
                        .date2sql($po_line->req_del_date) . "',"
                        .db_escape($po_line->price) . ", "
-                       .db_escape($po_line->quantity) . ")";
-               
+                       .db_escape($po_line->quantity) . ", "
+                       .db_escape($po_line->qty_received) . ")";
                db_query($sql, "One of the purchase order detail records could not be updated");
     }
 
        // add_comments(ST_PURCHORDER, $po_obj->order_no, $po_obj->orig_order_date, $po_obj->Comments);
 
        add_audit_trail($po_obj->trans_type, $po_obj->order_no, Today(), _("Updated."));
+       hook_db_postwrite($po_obj, ST_PURCHORDER);
        commit_transaction();
 
        return $po_obj->order_no;
@@ -118,8 +123,9 @@ function update_po(&$po_obj)
 
 function read_po_header($order_no, &$order)
 {
-       $sql = "SELECT ".TB_PREF."purch_orders.*, ".TB_PREF."suppliers.supp_name, ".TB_PREF."suppliers.tax_group_id,
-               ".TB_PREF."suppliers.curr_code, ".TB_PREF."locations.location_name
+       $sql = "SELECT ".TB_PREF."purch_orders.*, "
+               .TB_PREF."suppliers.*, "
+               .TB_PREF."locations.location_name 
                FROM ".TB_PREF."purch_orders, ".TB_PREF."suppliers, ".TB_PREF."locations
                WHERE ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
                AND ".TB_PREF."locations.loc_code = into_stock_location
@@ -132,10 +138,11 @@ function read_po_header($order_no, &$order)
 
        $myrow = db_fetch($result);
 
+       $order->trans_type = ST_PURCHORDER;
        $order->order_no = $order_no;
-       
+
        $order->set_supplier($myrow["supplier_id"], $myrow["supp_name"], $myrow["curr_code"],
-               $myrow['tax_group_id'], $myrow["tax_included"]);
+               $myrow['tax_group_id'], $myrow["tax_included"], @$myrow["tax_algorithm"]);
 
                $order->credit = get_current_supp_credit($order->supplier_id);
 
@@ -262,6 +269,8 @@ function get_sql_for_po_search_completed()
                AND porder.supplier_id = supplier.supplier_id
                AND location.loc_code = porder.into_stock_location ";
 
+       if (isset($_GET['supplier_id']))
+               $sql .= "AND supplier.supplier_id=".@$_GET['supplier_id']." ";
        if (isset($order_number) && $order_number != "")
        {
                $sql .= "AND porder.reference LIKE ".db_escape('%'. $order_number . '%');