stock_id = $stock_id; $this->startLocation = $startLocation; $this->parameters = $parameters; $this->qoh = get_qoh_on_date($this->stock_id, $startLocation); }} public function action() { if($this->parameters !== null && $this->parameters->mode == ScheduleMode::$Update) { $this->update(); } } public function update() { $orders = $this->orders(); $priorities = Lambda::harray(Lambda::map($orders, array(new _hx_lambda(array(&$orders), "ItemScheduler_0"), 'execute'))); $priorities->sort(array(new _hx_lambda(array(&$orders, &$priorities), "ItemScheduler_1"), 'execute')); $iter = $priorities->iterator(); $p = $iter->next(); $position = 0 - $priorities->length; { $_g = 0; while($_g < $orders->length) { $order = $orders[$_g]; ++$_g; $new_priority = DateTools::delta($p, 1000 * $position); update_order_detail_priority($order->id, $new_priority->toString()); $position += 1; $p = $iter->next(); unset($order,$new_priority); } } update_queue_quantity_for_item($this->stock_id); } public function needsUpdate() { return $this->parameters !== null && $this->parameters->mode == ScheduleMode::$Move; } public function purcharseOrders() { $TB = FA::tb(); $sql = "SELECT SUM(quantity_ordered - quantity_received) as quantity\x0A\x09\x09\x09into_stock_location AS location\x0A\x09\x09\x09FROM " . $TB . "purch_order_details\x0A\x09\x09\x09NATURAL JOIN " . $TB . "purch_orders\x0A\x09\x09\x09WHERE item_code = \"" . $this->stock_id . "\"\x0A\x09\x09\x09AND quantity_ordered > quantity_received\x0A\x09\x09\x09GROUP by item_code,delivery_date, into_stock_location\x0A\x09\x09\x09ORDER by delivery_date"; return FA::query($sql); } public function locations() { $TB = FA::tb(); $sql = "SELECT * \x0A\x09\x09FROM " . $TB . "locations"; $_locs = new _hx_array(array()); if(null == _hx_qtype("FA")) throw new HException('null iterable'); $»it = FA::query($sql); while($»it->hasNext()) { $row = $»it->next(); $location = new Location($row); if($location->code === $this->startLocation) { $location->delivery = Date::fromTime(0); } else { if($location->delivery === null) { continue; } } $_locs->push($location); unset($location); } return $_locs; } public function orders() { $_g = $this; $rows = $this->loadOrders(); $orderList = new _hx_array(array()); $»it = $rows; while($»it->hasNext()) { $row = $»it->next(); $a = php_Lib::objectOfAssociativeArray($row); $order = $a; $order->priority = Date::fromString($a->pp); $order->quantity = $a->qty; $orderList->push($order); unset($order,$a); } if($this->parameters !== null) { $orderList->sort(array(new _hx_lambda(array(&$_g, &$orderList, &$rows), "ItemScheduler_2"), 'execute')); } { $_g1 = 0; while($_g1 < $orderList->length) { $order = $orderList[$_g1]; ++$_g1; unset($order); } } return $orderList; } public function loadOrders() { $tb = TB_PREF; $sql = "SELECT * , d.quantity as qty, d.priority AS pp\x0A\x09\x09FROM " . $tb . "denorm_order_details_queue d\x0A\x09\x09JOIN " . $tb . "sales_order_details od ON (od.id = d.id)\x0A\x09\x09JOIN " . $tb . "sales_orders so ON (so.order_no = d.order_id)\x0A\x09\x09WHERE stock_id = '" . $this->stock_id . "'\x0A\x09\x09AND od.trans_type = 30\x0A\x09\x09ORDER by d.priority"; return FA::query($sql); } public function formatLocation($location, $type, $left) { $cells = new _hx_array(array($type, $location->name, $location->quantityOnHand($this->stock_id, null), $left - $location->quantityOnHand($this->stock_id, null), $left, $location->code, ((_hx_equal($location->delivery->getTime(), 0)) ? "" : DateTools::format($location->delivery, "%F")), "", "")); $this->printRow($cells, new _hx_array(array("class = \"tableheader location\"", "id = \"loc_" . $location->code . "\""))); } public function formatOrder($order, $left, $date) { $row_id = ItemScheduler::orderId($order); $attributes = new _hx_array(array("id = \"" . $row_id . "\"")); $classes = new _hx_array(array()); $before = $left + $order->quantity; if($before < 0) { $classes->push("soldout"); } else { if($left < 0) { $classes->push("partial"); } else { $classes->push("full"); } } $required_by = FA::sql2date($order->required_date); if($required_by === null) { $required_by = FA::sql2date($order->delivery_date); } if($required_by->getTime() < $date->getTime()) { $classes->push("late"); } else { $classes->push("on_time"); } $cells = new _hx_array(array($order->order_id, "debtor_no) . "\">" . Std::string($order->deliver_to) . "", "quantity) . "\">", $before, $left, $order->from_stk_loc, $order->delivery_date, $order->required_date, $order->comment)); $attributes->push("class=\"" . $classes->join(" ") . "\""); $this->printRow($cells, $attributes); } public function printRow($tds, $attributes) { php_Lib::hprint("