From: Maxime Bourget Date: Sat, 15 Jun 2013 14:40:36 +0000 (+0100) Subject: Use to pick table on dispatch. X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=7471bb23ac05a442d576ed81b2024ff2a7e2970c;p=order_line_extra.git Use to pick table on dispatch. --- diff --git a/hooks.php b/hooks.php index 5b26249..026f2d2 100644 --- a/hooks.php +++ b/hooks.php @@ -8,8 +8,9 @@ // ---------------------------------------------------------------- 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'; @@ -87,6 +88,38 @@ class hooks_order_line_extra extends hooks { $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 @@ -125,6 +158,9 @@ class hooks_order_line_extra extends hooks { $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); + } diff --git a/includes/picking.inc b/includes/picking.inc index d4141dc..3591a77 100644 --- a/includes/picking.inc +++ b/includes/picking.inc @@ -78,11 +78,14 @@ class Picker { } -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; } @@ -140,12 +143,16 @@ function insert_pick($sku, $order_id, $detail_id, $debtor_no, $branch_code, $to_ } -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; @@ -166,4 +173,10 @@ function update_pick($detail_id, $to_pick) { 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); + } +} +