X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=hooks.php;h=6cb3ff82a94031d362d3eaae98b39ad03098adbf;hb=ee3469d3ffd74d2a6be87d3dd0a9541a14bcdfde;hp=818fe7a3fc2ac3219151eb0efba5f05e8012fbfa;hpb=58c6369b4a4e57e3708393900fab9d2fdbd6759f;p=order_line_extra.git diff --git a/hooks.php b/hooks.php index 818fe7a..6cb3ff8 100644 --- a/hooks.php +++ b/hooks.php @@ -83,18 +83,25 @@ class hooks_order_line_extra extends hooks { } function db_postwrite($cart, $trans_type) { - if(!is_a($cart, "Cart") ) return; + if(is_a($cart, "Cart")) { // It's a cart. Find all the stock_id and update the cache table foreach($cart->line_items as $line_no => $item) { $stock_id = $item->stock_id; update_queue_quantity_for_item($stock_id); update_qoh_for_item($stock_id); + } + } + else if (isset($trans_type) && $trans_type == "order_xtra") { + $stock_ids = stock_id_from_detail($cart); + if($stock_ids) foreach($stock_ids as $stock_id) { + update_queue_quantity_for_item($stock_id); + update_qoh_for_item($stock_id); + } } // update null fields of new entered orders. - // - $types = array(ST_SALESORDER); + $types = array(ST_SALESORDER, 'order_xtra'); if(in_array($trans_type, $types)) update_order_detail_defaults(); } @@ -110,4 +117,19 @@ class hooks_order_line_extra extends hooks { } } } + +function stock_id_from_detail($detail_ids) { + if(empty($detail_ids)) return null; + $stock_ids = array(); + $ids = implode(', ', $detail_ids); + $sql = " SELECT DISTINCT stk_code + FROM ".TB_PREF."sales_order_details + WHERE id IN ($ids)"; + $result = db_query($sql); + while($row=db_fetch($result)) { + array_push($stock_ids, $row['stk_code']); + } + + return $stock_ids; +} ?>