}
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();
}
}
}
}
+
+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;
+}
?>