Established new hooks class convention.
[fa-stable.git] / sales / includes / db / sales_delivery_db.inc
index 8678aae84e9ed510f11dfd2827818588a1bbf122..5c269406349b06a7aeadb09e9db755eb2035dc4f 100644 (file)
@@ -20,6 +20,8 @@ function write_sales_delivery(&$delivery,$bo_policy)
        if (is_array($trans_no)) $trans_no = key($trans_no);
 
        begin_transaction();
+       $delivery->bo_policy = $bo_policy;
+       hook_db_prewrite($delivery, ST_CUSTDELIVERY);
 
        $customer = get_customer($delivery->customer_id);
        $delivery_items_total = $delivery->get_items_total_dispatch();
@@ -90,7 +92,7 @@ function write_sales_delivery(&$delivery,$bo_policy)
                        $stock_gl_code = get_stock_gl_code($delivery_line->stock_id);
 
                        /* insert gl_trans to credit stock and debit cost of sales at standard cost*/
-                       if ($delivery_line->standard_cost != 0) {
+                       if (is_inventory_item($delivery_line->stock_id) && $delivery_line->standard_cost != 0) {
 
                                /*first the cost of sales entry*/
                                // 2008-08-01. If there is a Customer Dimension, then override with this,
@@ -140,6 +142,7 @@ function write_sales_delivery(&$delivery,$bo_policy)
                        $Refs->save(ST_CUSTDELIVERY, $delivery_no, $delivery->reference);
        }
 
+       hook_db_postwrite($delivery, ST_CUSTDELIVERY);
        commit_transaction();
 
        return $delivery_no;
@@ -152,6 +155,8 @@ function void_sales_delivery($type, $type_no, $transactions=true)
        if ($transactions)
                begin_transaction();
 
+       hook_db_prevoid($type, $type_no);
+       
        void_gl_trans($type, $type_no, true);
 
        // reverse all the changes in the sales order