Initialized upgrade procedures for FA 2.4
[fa-stable.git] / purchasing / includes / db / po_db.inc
index 41ed94f09872aa42921849ad7126c6ab85f339e3..2a88e0cb15bb995e0bedb9ca6da855027bf29b79 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,9 +28,11 @@ 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, requisition_no, into_stock_location, delivery_address, total) VALUES(";
+     $sql = "INSERT INTO ".TB_PREF."purch_orders (supplier_id, Comments, ord_date, reference, 
+       requisition_no, into_stock_location, delivery_address, total, tax_included) VALUES(";
      $sql .= db_escape($po_obj->supplier_id) . "," .
          db_escape($po_obj->Comments) . ",'" .
          date2sql($po_obj->orig_order_date) . "', " .
@@ -37,7 +40,8 @@ function add_po(&$po_obj)
          db_escape($po_obj->supp_ref) . ", " .
          db_escape($po_obj->Location) . ", " .
          db_escape($po_obj->delivery_address) . ", " .
-         db_escape($po_obj->get_trans_total()) . ")";
+         db_escape($po_obj->get_trans_total()). ", " .
+         db_escape($po_obj->tax_included) . ")";
 
        db_query($sql, "The purchase order header record could not be inserted");
 
@@ -62,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;
@@ -72,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) . ",
@@ -79,7 +85,8 @@ function update_po(&$po_obj)
                into_stock_location=" . db_escape($po_obj->Location). ",
                ord_date='" . date2sql($po_obj->orig_order_date) . "',
                delivery_address=" . db_escape($po_obj->delivery_address).",
-               total=". db_escape($po_obj->get_trans_total());
+               total=". db_escape($po_obj->get_trans_total()).",
+               tax_included=". db_escape($po_obj->tax_included);
     $sql .= " WHERE order_no = " . $po_obj->order_no;
        db_query($sql, "The purchase order could not be updated");
 
@@ -106,6 +113,7 @@ function update_po(&$po_obj)
        // 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;
@@ -123,17 +131,18 @@ function read_po_header($order_no, &$order)
                AND ".TB_PREF."purch_orders.order_no = ".db_escape($order_no);
 
        $result = db_query($sql, "The order cannot be retrieved");
-_vd($sql);
+
        if (db_num_rows($result) == 1)
        {
 
        $myrow = db_fetch($result);
 
+       $order->trans_type = ST_PURCHORDER;
        $order->order_no = $order_no;
-       $order->supplier_id = $myrow["supplier_id"];
-       $order->supplier_name = $myrow["supp_name"];
-       $order->curr_code = $myrow["curr_code"];
-               $order->tax_group_id = $myrow['tax_group_id'];
+       
+       $order->set_supplier($myrow["supplier_id"], $myrow["supp_name"], $myrow["curr_code"],
+               $myrow['tax_group_id'], $myrow["tax_included"], $myrow["tax_algorithm"]);
+
                $order->credit = get_current_supp_credit($order->supplier_id);
 
        $order->orig_order_date = sql2date($myrow["ord_date"]);