Add pre_hold_offset. hook quantity + item scheduler.
[order_line_extra.git] / hooks.php
index 6cb3ff82a94031d362d3eaae98b39ad03098adbf..b472aefd92431af68156932ea14334bdf2f44ccd 100644 (file)
--- a/hooks.php
+++ b/hooks.php
@@ -8,6 +8,7 @@
 // ----------------------------------------------------------------
 define ('SS_ORDERLINEX', 100<<8);
 
+include_once('includes/order_xtra_config.inc');
 include_once('includes/db_order_lines.inc');
 
 class hooks_order_line_extra extends hooks {
@@ -72,14 +73,20 @@ class hooks_order_line_extra extends hooks {
                        $date = array_shift($opts);
                        $qoh = array_shift($opts);
 
-                       $sql = "select quantity_before from ".TB_PREF."denorm_order_details_queue where id = $detail_id";
+                       $sql = "SELECT quantity_before, hold_until_date
+                                                       FROM ".TB_PREF."denorm_order_details_queue
+                                                       NATURAL JOIN ".TB_PREF."sales_order_details
+                                                       WHERE id = $detail_id";
                        $result = db_query($sql);
                        $quantity_before = 0;
                        if($row=db_fetch($result)) {
                                $quantity_before = $row['quantity_before'];
+                               $hold_until = sql2date($row['hold_until_date']);
+                               if($qoh<=$quantity_before) return array(0, 'stockmankobg');
+                               if(OrderXtraConfig::early($hold_until, $date)) return array(0, 'early');
                                }
 
-                       return max($qoh - $quantity_before, 0);
+                       return array(max($qoh - $quantity_before, 0), '');
                }
 
                function db_postwrite($cart, $trans_type) {