From 1b576014fb5ba65fb02b576d67a09096ba6bf9b6 Mon Sep 17 00:00:00 2001 From: Maxime Bourget Date: Fri, 21 Jun 2013 11:46:59 +0100 Subject: [PATCH] Fix get_allowed and change to get_dispatchable quantity hook --- hooks.php | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/hooks.php b/hooks.php index 3f146c7..480d503 100644 --- a/hooks.php +++ b/hooks.php @@ -83,11 +83,14 @@ class hooks_order_line_extra extends hooks { return $this->update_databases($company, $updates, $check_only); } - function get_allowed_quantity($detail_id, $opts) { + function get_dispatchable_quantity($line_item, $opts) { $location = array_shift($opts); $date = array_shift($opts); $qoh = array_shift($opts); + $detail_id = $line_item->id; + $quantity = $line_item->qty_dispatched; + /* We have 2 methods to estimate the allowed quantity. * the first use the different priority to estimate what's available. * This is the same algorithm used to auto pick items. @@ -112,33 +115,47 @@ class hooks_order_line_extra extends hooks { $row = db_fetch($result); if($row) { $available = $row['quantity']; - return array($available, 'picked limited'); + if($available == 0) { + return array(0, $qoh ? 'limited' : 'stockmankobg'); + } + else if($available < $quantity) { + return array($available, 'picked'); + } + else { + return array($quantity, 'picked'); + } } else { - return array(0, ''); + // hasn't been picked + return array(0, 'stockmankobg soldout'); } } else { - return $this->get_allowed_quantity_from_priority($detail_id, $location, $date, $qoh); + return $this->get_allowed_quantity_from_priority($detail_id, $quantity, $location, $date, $qoh); } } - function get_allowed_quantity_from_priority($detail_id, $location, $date, $qoh) { + function get_allowed_quantity_from_priority($detail_id, $quantity, $location, $date, $qoh) { + if($qoh == 0) return array(0, 'stockmankobg'); $sql = "SELECT quantity_before, hold_until_date FROM ".TB_PREF."denorm_order_details_queue JOIN ".TB_PREF."sales_order_details USING (id) WHERE id = $detail_id"; $result = db_query($sql); - $quantity_before = 0; + + $classes = array(); + $dispatchable = $quantity; if($row=db_fetch($result)) { $quantity_before = $row['quantity_before']; + $qoh = max(0, $qoh-$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'); + $dispatchable = min($quantity, $qoh); + if($dispatchable < $quantity) array_push($classes, 'limited'); + if(OrderXtraConfig::early($hold_until, $date)) array_push($classes, 'early'); } - return array(max($qoh - $quantity_before, 0), 'limited'); + return array($dispatchable, implode(' ', $classes)); } function db_postwrite($cart, $trans_type) { -- 2.30.2