if ($obj_product->category_top_id != $segment['categories_top_id']) {
     //WRONG SEGMENT, REJECT BIN IN
     $result['status'] = 'WRONG-SEGMENT';
 } else {
     //USE STARS for choosing best selling rack:
     $i_rack_flag = $obj_product->stars < 2 ? 'N' : 'B';
     //Find open depot orders that can be closed by saving the ID to $items
     //Check first if outsourcing orders
     if (isset($item) && $is_outsourced) {
         //if yes (outsourcing)
         $items = array();
         $items[$item['depot_orders_id']] = $item;
         $dp_closed[] = 'DP-' . $item['depot_orders_id'];
     } else {
         //if not (normal bin ins)
         $items = $class_do->searchDepotOrder($segments_id, $products_id, $articles_id, $REQUIRED_STATUS);
         if (count($items) > 0) {
             $counter = 0;
             foreach ($items as $item_id => $i) {
                 if ($counter + $i['quantity'] > $quantity) {
                     unset($items[$item_id]);
                 } else {
                     $counter += $i['quantity'];
                     $dp_closed[] = 'DP-' . $item_id;
                     //CHECK IF WE SHOULD PUT IT TO MMO RACK
                     $i_src = null;
                     if ($i['trans_type'] == Order::ORDER_TYPE_SALES_PARTNER) {
                         $i_src = Order::getOldOrderFunctionSP()->retrieveItemDetail($i['trans_id']);
                     } elseif ($i['trans_type'] == Order::ORDER_TYPE_JULIE_GRACE) {
                         $i_src = Order::getOldOrderFunctionJG()->retrieveProductDetail($i['trans_id']);
                     }
                list($dp, $item_id) = explode('-', $dpid);
                if (is_numeric($item_id)) {
                    $do = $class_do->retrieveDetail($item_id);
                    if ($class_do->isNonRefillOrder($do['trans_type']) && ($do['status'] == '22' || $do['status'] == $status_otw)) {
                        $new_status = $class_do->updateStatus($do['depot_orders_id'], $status_close, $session_userinfo['username']);
                    }
                }
            } else {
                if ($group_name == $blank_groupname) {
                    $group_name = '';
                }
                $ean = tep_db_prepare_input($_POST['ean']);
                use_class('products_ean');
                $class_ean = new products_ean();
                $product_info = $class_ean->getProductArticle($ean);
                $do = $class_do->searchDepotOrder(SEGMENT_ID_HAMBURG, $product_info['products_id'], $product_info['products_articles_id'], $status_otw, $group_name);
                if (count($do) > 0) {
                    $do_first = array_shift($do);
                    $new_status = $class_do->updateStatus($do_first['depot_orders_id'], $status_close, $session_userinfo['username']);
                }
            }
        }
        echo isset($new_status) && $new_status == '8' ? $ean : 'FAIL';
        exit;
    }
}
$open_names = $class_do->retrieveGroupNameList('status=7');
array_unshift($open_names, $blank_groupname);
array_unshift($open_names, $nonrefill_orders_name);
array_unshift($open_names, '');
//START TEMPLATE