// ----------------------------------------------------------------
define ('SS_ORDERLINEX', 100<<8);
-include_once('includes/order_xtra_config.inc');
-include_once('includes/db_order_lines.inc');
+require_once('includes/order_xtra_config.inc');
+require_once('includes/db_order_lines.inc');
+require_once('includes/picking.inc');
class hooks_order_line_extra extends hooks {
var $module_name = 'order_line_extra';
$date = array_shift($opts);
$qoh = array_shift($opts);
+ /* 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.
+ * The second rely on what's being choose to be picked up.
+ * If an order has been selected to be picked up, only the items and the quantity picked up
+ * needs to be available.
+ */
+ $sql = "SELECT count(*)
+ FROM 0_sales_order_details
+ WHERE order_no IN (SELECT distinct order_no
+ FROM 0_sales_order_details
+ WHERE id = $detail_id)";
+
+ $result = db_query($sql);
+ if(db_num_rows($result) > 0) {
+ $result = db_query(pick_query($detail_id));
+ $row = db_fetch($result);
+ if($row) {
+ $available = $row['quantity'];
+ return array($available, 'picked');
+ }
+ else {
+ return array(0, '');
+ }
+
+ }
+ else {
+ return get_allowed_quantity_from_priority($detail_id, $location, $date, $qoh);
+ }
+ }
+
+ function get_allowed_quantity_from_priority($detail_id, $location, $date, $qoh) {
$sql = "SELECT quantity_before, hold_until_date
FROM ".TB_PREF."denorm_order_details_queue
NATURAL JOIN ".TB_PREF."sales_order_details
$types = array(ST_SALESORDER, 'order_xtra');
if(in_array($trans_type, $types)) update_order_detail_defaults();
+ // Clean to_pick table on dispatch
+ if($trans_type == ST_CUSTDELIVERY) clean_pickup_for_dispatch($cart);
+
}
}
-function pick_query() {
- return "SELECT detail_id, -sum(quantity) as quantity
+function pick_query($detail_id=null) {
+ $sql = "SELECT detail_id, -sum(quantity) as quantity
FROM ".TB_PREF."topick
- WHERE type IN ('order', 'booked')
- GROUP BY detail_id ";
+ WHERE type IN ('order', 'booked')";
+ if($detail_id) $sql .= " AND detail_id = $detail_id";
+ else $sql .= " GROUP BY detail_id ";
+
+ return $sql;
}
}
-function update_pick($detail_id, $to_pick) {
- // delete existing
+function delete_pick($detail_id) {
$sql = "DELETE FROM ".TB_PREF."topick
WHERE detail_id = $detail_id
";
- db_query($sql);
+ return db_query($sql);
+}
+
+function update_pick($detail_id, $to_pick) {
+ // delete existing
+ delete_pick($detail_id);
if($to_pick ==0) return;
insert_pick($stock_id, $order_id, $detail_id, $debtor_no, $branch_code, $to_pick, $quantity);
}
+function clean_pickup_for_dispatch($cart) {
+ foreach($cart->line_items as $line) {
+ delete_pick($line->src_id);
+ }
+}
+