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.
$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) {