function drawPLthumb($products_linking_id, $products_id, $hide = false, $show_remove = false)
{
    $obj_product = new Product($products_id);
    $hidden = $hide === true ? 'style="display:none;"' : '';
    $l = '<div id="pl-' . $products_linking_id . '" class="pro-thumb" ' . $hidden . '>';
    $l .= '<div>' . $obj_product->displayImage(IMAGE_SIZE_THUMBNAIL_2, IMAGE_SIZE_THUMBNAIL_2) . '</div>';
    $l .= '<div>' . $obj_product->displayIDAndCode() . '</div>';
    if ($show_remove) {
        $l .= '<div title="Click to remove this product" class="red">(x) remove</div>';
    }
    $l .= '</div>';
    return $l;
}
function getDisplay($pid, $spid, $amvd_provision_rate, $row_class = 'o')
{
    global $class_jc;
    $result = '';
    $obj_product = new Product($pid);
    $have_amvd_catalog = $obj_product->isAddedToSalesPartner($spid);
    $is_active = $obj_product->isActiveInSalesPartner($spid);
    $products_image = $obj_product->displayImage(IMAGE_SIZE_THUMBNAIL_1, IMAGE_SIZE_THUMBNAIL_1);
    $info = '<div style="margin-bottom:20px;">' . $obj_product->displayIDAndCode() . '</div>';
    $info .= '<div class="w150" style="margin:0 auto;">' . $obj_product->displayRecentSoldTable() . '</div>';
    $navids = array('0' => 'Please select a navigation...');
    $navids_opts = retrieveNavIDs($spid, 'bn');
    foreach ($navids_opts as $n_id => $n_name) {
        //if doesn't work in dev environment, it could be caused by umlauts
        //in the navigation name. Can be fixed by adding htmlspecialchars or
        //but we don't need it for live (sahat- 16.09.2014)
        $navids[$n_id] = $n_name;
    }
    $navid = $have_amvd_catalog ? $obj_product->getSalesPartnerMainNavigationID($spid) : null;
    $navigation = '<select class="navigation input">' . loadComboListFromArray($navids, null, $navid, false) . '</select>';
    $result .= '<tr id="' . $pid . '" class="' . $row_class . '">';
    $result .= '<td class="img">' . $products_image . '</td>';
    $result .= '<td class="name">' . $info . '</td>';
    $result .= '<td class="pb">' . $navigation . '</td>';
    $btn_update_text = $is_active ? 'Update' : 'Activate';
    $btn_add = '<input type="button" style="width:90px;" class="add button blue" value="Add" title="Add this product to AM.VD Catalogue"/>';
    $btn_update = '<input type="button" style="width:90px;" class="update button blue" value="' . $btn_update_text . '" title="Update and activate this product on AM.VD Catalogue"/>';
    $btn_ignore = '<input type="button" style="width:90px;" class="ignore button" value="Ignore" title="Ignore from list"/>';
    $btn_deactivate = '<input type="button" style="width:90px;" class="deactivate button blue" value="Deactivate" title="Deactivate or remove from AM.VD catalog"/>';
    $i_hidden = '<input type="hidden" name="jcid" value="' . $obj_product->getSalesPartnerCatalogID($spid) . '"/>';
    if ($have_amvd_catalog) {
        $btn = $i_hidden . $btn_update . '<br/>' . $btn_deactivate;
    } else {
        $btn = $btn_add . '<br/>' . $btn_ignore;
    }
    $result .= '<td class="act">' . $btn;
    $result .= '<input type="hidden" class="pid" value="' . $pid . '"/>';
    $result .= '</td>';
    $result .= '</tr>';
    return $result;
}
function loadProductRow($pid, $spid, $pos, $curgroup_id)
{
    global $class_jc, $header;
    use_class('Product');
    $product = new Product($pid);
    $sp_catalog = $class_jc->retrieveCatalog($spid, "jc.products_id = '{$pid}'");
    $cols = array();
    foreach ($header as $hk => $hv) {
        $value = '';
        switch ($hk) {
            case 'img':
                $value .= $product->displayImage(IMAGE_SIZE_THUMBNAIL_1, IMAGE_SIZE_THUMBNAIL_1);
                break;
            case 'name':
                $value .= '<strong>' . $product->brand_name . '</strong>';
                $value .= '<br /><a href="?open=product-detail&amp;products_id=' . $product->id . '" target="_blank">' . $product->id . ' / ' . $product->code . '</a>';
                break;
            case 'imgup':
                $img_reupload = $sp_catalog[0]['image_uploaded'] == '0' ? 'checked="checked" ' : '';
                $tooltip = $sp_catalog[0]['image_uploaded'] == '0' ? "Uncheck to exclude this product image when generate catalog" : "Check to include this product image when generate catalog";
                $value = '<input type="checkbox" name="imguploaded" value="0" title="' . $tooltip . '" ' . $img_reupload . '/>';
                break;
            case 'prcup':
                $price_reupload = $sp_catalog[0]['price_uploaded'] == '0' ? 'checked="checked" ' : '';
                $tooltip = $sp_catalog[0]['price_uploaded'] == '0' ? "Uncheck to exclude this product data when generate catalog" : "Check to include this product data when generate catalog";
                $value = '<input type="checkbox" name="priceuploaded" value="0" title="' . $tooltip . '" ' . $price_reupload . '/>';
                break;
        }
        if ($value == '') {
            $value = '&nbsp;';
        }
        $cols[$hk] = $value;
    }
    $productrow = '<tr id="temp-' . $pid . '">';
    foreach ($cols as $ck => $cv) {
        $productrow .= '<td class="' . $ck . '">' . $cv . '</td>';
    }
    $productrow .= '</tr>';
    return $productrow;
}
Example #4
0
     $query .= " LIMIT {$maxproducts}";
     $query .= "))";
     $query .= "AS dt";
     $query .= " GROUP BY products_id";
     $query .= " ORDER BY order_date_max DESC";
     $query .= " LIMIT {$maxproducts}";
     $r = tep_db_query($query);
     $products = array();
     while ($row = tep_db_fetch_array($r)) {
         $products[$row['products_id']] = $row;
     }
     if (count($products) > 0) {
         $ajaxResult['products_id'] = implode(',', array_reverse(array_keys($products)));
         foreach ($products as $pid => $row) {
             $obj_product = new Product($pid);
             $product_image = $obj_product->displayImage(IMAGE_SIZE_THUMBNAIL_2, IMAGE_SIZE_THUMBNAIL_2, '', false, '', Product::IMAGE_LINKTO_PRODUCT_DETAIL);
             $ajaxResult['img-' . $pid] = '<div id="rb-pid-' . $pid . '" style="float:left;margin:0 5px 20px 4px;">' . $product_image . '</div>';
         }
     } else {
         $ajaxResult['products_id'] = 'none';
     }
     echo ajaxReturn($ajaxResult);
     exit;
 }
 /*
 if($_POST['me_action']=='TODOSUSERCOUNTER') {
         use_class('minierp_users');
         $class_mu = new minierp_users();
         $userlist = $class_mu->retrieveList('status="1"','username ASC');
         $todos_counter = $class_td->userTodosCounter($userlist);
         $result = array();
 $content .= '<li><a href="#prodet-tab3b"><span>EAN &amp; More Length/Size</span></a></li>';
 $content .= '<li><a href="#prodet-tab2"><span>Elements Used</span></a></li>';
 if ($pc === false) {
     $content .= '<li><a href="#prodet-tab2b"><span>Manual PI</span></a></li>';
 }
 $content .= '<li><a href="#prodet-tab3"><span>Sales Partner Catalog</span></a></li>';
 $content .= '<li><a href="#prodet-tab4"><span>Forecasting</span></a></li>';
 $content .= '<li><a href="#prodet-tab5"><span>Finalize for Tradebyte</span></a></li>';
 $content .= '</ul>';
 //TAB "Main"
 $content .= '<div id="prodet-tab1" class="pro-detail">';
 //LEFT PANEL
 $content .= '<div id="left-panel" style="float:left;margin-top:10px;border:1px solid #efefef;padding:10px;background:#fff;">';
 $content .= '<div class="tac">' . ($products_brand != '' ? webImage($products_brand['brand_image'], IMAGE_SIZE_THUMBNAIL_2, '', $products_brand['brand_name']) : '<span class="red">Brand not yet set</span>') . '</div>';
 //$content .= webImageWithDetailLinkStars($products['products_image'], IMAGE_SIZE_THUMBNAIL_3, 0, "Main Image of Product $products_id", 'img-border', '', IMAGE_SIZE_BIG_1, 0, $products['stars'], 3, '', '', '', $product);
 $content .= $obj_product->displayImage(IMAGE_SIZE_THUMBNAIL_3, IMAGE_SIZE_THUMBNAIL_3_PORTRAIT);
 $content .= '<div class="tac" style="margin-top:10px;padding-left:20px;">&raquo; ';
 if ($products['products_status'] == '1') {
     $content .= '<a href="' . JNGWEBADDRESS . 'product_info.php?products_id=' . $products_id . '" target="_blank">View in J&amp;G Website</a>';
 } else {
     $content .= '<span class="notice">Inactive in J&amp;G Website</span>';
 }
 $content .= ' &laquo;';
 foreach ($products_sp_link as $jng_sp_id => $spl) {
     $link_text = 'Search in ' . $products_sp[$jng_sp_id]['package_prefix'] . ' Website';
     $content .= '<br />&raquo; ';
     $content .= $spl == '' ? '<span class="notice pointer" title="Required data for search is missing" onclick="alert($(this).attr(\'title\'));">' . $link_text . '</span>' : '<a href="' . $spl . '" target="_blank">' . $link_text . '</a>';
     $content .= ' &laquo; ';
 }
 $content .= '</div>';
 $content .= '<div class="tac" style="margin-top:20px;">';
 public function renderRow($order_type, $orders_items_id, $template_row = self::ROW_TEMPLATE_DEFAULT, $is_order_first_row = false)
 {
     use_class('Product');
     $order_item_data = $this->retrieveOrdersItemsDetail($order_type, $orders_items_id);
     $row_data = array();
     //SET GENERAL VARS VALUES
     $products_id = $order_item_data['products_id'];
     $articles_id = $order_item_data['products_articles_id'];
     $obj_product = new Product($products_id);
     $product_image = $obj_product->displayImage(80, 80);
     $product_image_thumbid = "{$products_id}-{$articles_id}";
     $article_no_link = '?open=product-detail&amp;products_id=' . $products_id;
     switch ($this->filters_status) {
         case '1':
             $is_sp = $order_type == self::ORDER_TYPE_SP;
             $is_prepayment = strtoupper($order_item_data['payment_method']) == strtoupper(PAYMENT_METHOD_BANK_TRANSFER) || strtoupper($order_item_data['payment_method']) == strtoupper(PAYMENT_METHOD_PREPAYMENT);
             $is_unpaid_prepayment = $is_prepayment && !conditionPrepaymentIsPaid($order_item_data, $is_sp);
             break;
     }
     if ($order_type == self::ORDER_TYPE_SP) {
         use_class('products_minierp');
         $class_pm = new products_minierp();
         //self::ROW_DATA_LEADTIME_OR_DATE
         $order_date = $order_item_data['order_date'];
         //self::ROW_DATA_CYCLETIME DATA
         $previous_status_date = $this->filters_status == 4 ? $order_item_data['status_date_prod'] : $order_item_data['status_date'];
         //self::ROW_DATA_CUSTOMER_OR_ORDER_NO DATA
         $order_id = $order_item_data['order_id'];
         $orders_number = $order_item_data['order_id'];
         $order_no_link = '?open=customer-care-order-detail&amp;source=SP&amp;id=' . $order_item_data['jng_sp_orders_id'] . '&amp;hidemenu=true';
         $customer_name = $order_item_data['customer_name'];
         $cust_link = '?open=sp-customer&amp;id=' . $order_item_data['jng_sp_customers_id'] . '&amp;hidemenu=true';
         $cust_name = '<a href="' . $cust_link . '" class="view_webpage" >' . $customer_name . '</a>';
         //self::ROW_DATA_ORDER_ID DATA
         $source_name = $order_item_data['package_prefix'];
         $barcode_id = strtoupper(self::ORDER_TYPE_SP) . '-' . $order_item_data['jng_sp_orders_items_id'];
         $barcode_id_link = '?open=sp-order-history&amp;oi_id=' . $order_item_data['jng_sp_orders_items_id'] . '&amp;hidemenu=true';
         $crown_link = '?open=sp-customers-special-detail&amp;id=' . $order_item_data['jng_sp_customers_id'] . '&amp;hidemenu=true';
         //self::ROW_DATA_ARTICLE_NO DATA
         $product_image_thumbid .= "-{$order_item_data['jng_sp_id']}";
         $article_no = $order_item_data['article_number'];
         //self::ROW_DATA_PRICE DATA
         $products_price = $order_item_data['price'];
         //self::ROW_DATA_QUANTITY DATA
         $order_quantity = $order_item_data['order_quantity'];
         //self::ROW_DATA_MARGIN DATA
         $mat_exp = $order_item_data['material_expenses'] > 0 ? $order_item_data['material_expenses'] : $order_item_data['current_mat_exp'];
         $product_margin = number_format($class_pm->calculateMargin($order_item_data['price'], $mat_exp), 1) . '%';
         $product_margin = '<span class="' . ($class_pm->priceMargindIsGood($order_item_data['price'], $product_margin) ? 'green' : 'red') . '">' . $product_margin . '</span>';
         //self::ROW_DATA_ACTION DATA
         //Tab Unpaid Prepayment
         if ($this->filters_status == 1 && $this->filters_sub_status == '0') {
             if ($order_item_data['jng_sp_id'] == '8') {
                 $action = '<span class="green">Waiting Payment Status</span>';
             } else {
                 if ($order_item_data['last_sent_date'] == '') {
                     $action = '<span class="green">Reminder Not Sent</span>';
                 } else {
                     $overtime = strtotime($order_item_data['last_sent_date']) < strtotime('-' . PAYMENT_METHOD_BANK_TRANSFER_OVERDUE);
                     if ($order_item_data['sent_count'] > 1) {
                         $action = '<span class="red">Cancel Notification Sent</span>';
                     } else {
                         $action = '<span class="blue">Reminder Sent</span>';
                     }
                 }
             }
         }
     } elseif ($order_type == self::ORDER_TYPE_JG) {
         //self::ROW_DATA_LEADTIME_OR_DATE
         $order_date = $order_item_data['date_purchased'];
         //self::ROW_DATA_CYCLETIME DATA
         $previous_status_date = $this->filters_status == 4 ? $order_item_data['status_date_prod'] : $order_item_data['status_date'];
         //self::ROW_DATA_CUSTOMER_OR_ORDER_NO DATA
         $order_id = $order_item_data['orders_no'];
         $orders_number = $order_item_data['orders_no'];
         $order_no_link = '?open=customer-care-order-detail&amp;source=JG&amp;id=' . $order_item_data['orders_id'] . '&amp;hidemenu=true';
         $customer_name = $order_item_data['customers_name'];
         $cust_link = '?open=customer&amp;id=' . $order_item_data['customers_id'] . '&amp;hidemenu=true';
         $cust_name = '<a href="' . $cust_link . '" class="view_webpage" >' . $customer_name . '</a>';
         //self::ROW_DATA_ORDER_ID DATA
         $source_name = 'J&G';
         $barcode_id = strtoupper(self::ORDER_TYPE_JG) . '-' . $order_item_data['orders_products_id'];
         $barcode_id_link = '?open=sp-order-history&amp;opid=' . $order_item_data['orders_products_id'] . '&amp;hidemenu=true';
         $crown_link = '?open=customers-special-detail&amp;id=' . $order_item_data['customers_id'] . '&amp;hidemenu=true';
         //self::ROW_DATA_ARTICLE_NO DATA
         $article_no = $order_item_data['products_model'] . ($order_item_data['products_length'] > 0 ? '_' . textLength($order_item_data['products_length'], false) : '');
         //self::ROW_DATA_PRICE DATA
         $products_price = $order_item_data['final_price'];
         //self::ROW_DATA_QUANTITY DATA
         $order_quantity = $order_item_data['products_quantity'];
         //self::ROW_DATA_MARGIN DATA
         $product_margin = '';
         //self::ROW_DATA_ACTION DATA
         //Tab Unpaid Prepayment
         if ($this->filters_status == 1 && $this->filters_sub_status == '0') {
             if ($order_item_data['last_sent_date'] == '') {
                 $action = '<span class="green">Reminder Not Sent</span>';
             } else {
                 $overtime = strtotime($order_item_data['last_sent_date']) < strtotime('-' . PAYMENT_METHOD_BANK_TRANSFER_OVERDUE);
                 if ($order_item_data['sent_count'] > 1) {
                     $action = '<span class="red">Cancel Notification Sent</span>';
                 } else {
                     $action = '<span class="blue">Reminder Sent</span>';
                 }
             }
         }
     } else {
         use_class('depot_orders');
         $class_do = new depot_orders();
         //self::ROW_DATA_LEADTIME_OR_DATE
         $order_date = $order_item_data['order_date'];
         //self::ROW_DATA_CYCLETIME DATA
         $previous_status_date = $this->filters_status == 4 ? $order_item_data['status_date_prod'] : $order_item_data['update_time'];
         //self::ROW_DATA_CUSTOMER_OR_ORDER_NO DATA
         $order_id = '';
         $customer_name = $order_item_data['customer_name'];
         $depot_orders_info = $class_do->translateOrderSource($order_item_data['trans_type'], $order_item_data['trans_id'], true, null, $products_id);
         $cust_name = $customer_name;
         if ($depot_orders_info != '') {
             $cust_name = $cust_name . ($cust_name != '' ? " <br/>{$depot_orders_info}" : $depot_orders_info);
             if ($order_item_data['group_name'] != '') {
                 $cust_name .= ': ' . $order_item_data['group_name'];
             }
         }
         //self::ROW_DATA_ORDER_ID DATA
         $source_name = 'DP';
         $barcode_id = strtoupper(self::ORDER_TYPE_DP) . '-' . $order_item_data['depot_orders_id'];
         $barcode_id_link = '?open=depot-order&amp;id=' . $order_item_data['depot_orders_id'] . '&amp;hidemenu=true';
         //self::ROW_DATA_ARTICLE_NO DATA
         $article_no = $order_item_data['article_number'];
         //self::ROW_DATA_PRICE DATA
         $products_price = $order_item_data['price'];
         //self::ROW_DATA_QUANTITY DATA
         $order_quantity = $order_item_data['quantity'];
         //self::ROW_DATA_MARGIN DATA
         $product_margin = '';
     }
     //FIRST ROW OF ORDER
     if ($is_order_first_row) {
         $crown_img_col = array('V' => 'vip', 'B' => 'black');
         if ($order_item_data['list_type'] != '' && array_key_exists($order_item_data['list_type'], $crown_img_col)) {
             $crown_img_title = array('V' => 'VIP Customer', 'B' => 'Blacklist Customer');
             $crown_img = '<a href="' . $crown_link . '" class="view_webpage">';
             $crown_img .= '<img src="images/list-' . $crown_img_col[$order_item_data['list_type']] . '.gif" title="' . $crown_img_title[$order_item_data['list_type']] . '" />';
             $crown_img .= '</a> ';
             $cust_crown = $crown_img;
         } else {
             $cust_crown = '';
         }
         $cust_order_count = ' <sup>' . $order_item_data['customers_order_count'] . '</sup>';
         if ($orders_number == '' || is_null($orders_number)) {
             $order_no = '';
         } else {
             $order_no = '<br /><small>order no:</small>&nbsp;&nbsp;<a href="' . $order_no_link . '" class="view_webpage">' . $order_id . '</a>';
         }
         $row_data[self::ROW_DATA_CUSTOMER_OR_ORDER_NO] = $cust_crown . $cust_name . $cust_order_count . $order_no;
         $row_data[self::ROW_DATA_SOURCE] = strtoupper($source_name);
     }
     $row_data[self::ROW_DATA_LEADTIME_OR_DATE] = $is_unpaid_prepayment || $this->filters_status > 9 ? date('d-M-y', strtotime($order_date)) : displayLeadTime($order_item_data['leadtime_start_date'], strtotime($order_item_data['leadtime_start_date']));
     if ($this->filters_status == 1 && $order_item_data['update_time'] == '') {
         $order_item_data['update_time'] = $order_item_data['leadtime_start_date'];
     }
     $row_data[self::ROW_DATA_CYCLETIME] = displayCycleTime($previous_status_date);
     $row_data[self::ROW_DATA_ORDER_ID] = '<a href="' . $barcode_id_link . '" class="view_webpage">' . $barcode_id . '</a>' . ($order_item_data['order_item_total'] > 1 ? ' <sup>' . $order_item_data['order_item_count'] . '/' . $order_item_data['order_item_total'] . '</sup>' : '');
     $row_data[self::ROW_DATA_ARTICLE_NO] = '<div class="thumb" thumbid="' . $product_image_thumbid . '">' . '<span>' . $product_image . '</span></div>' . '<div><a href="' . $article_no_link . '" target="_blank&amp;hidemenu=true" title="View Product Detail" ' . 'class="view_webpage">' . $article_no . '</a></div>';
     $row_data[self::ROW_DATA_PRICE] = number_format($products_price, 2);
     $order_quantity = intval($order_quantity);
     $row_data[self::ROW_DATA_QUANTITY] = $order_quantity;
     $row_data[self::ROW_DATA_MARGIN] = $product_margin;
     $el_link = '<a href="?open=products-elements-stock&amp;products_id=' . $products_id . '&amp;paid=' . $articles_id . '&amp;qty=' . $order_quantity . '&amp;status=' . $order_item_data['stock_status'] . '&amp;hidemenu=true" class="view_webpage"></a>';
     $pr_link = '<a href="javascript:void();" onclick="alert(\'Please use Finish Good Stock\');"></a>';
     $dp_link = '<a href="javascript:void();" onclick="alert(\'Please use Depot Stock\');"></a>';
     if ($this->filters_show_stock_status) {
         switch ($order_item_data['stock_status']) {
             case '0':
                 $stock_status = '<strong class="red">!</strong>';
                 if ($this->filters_status == 8 && ($order_type == self::ORDER_TYPE_SP || $order_type == self::ORDER_TYPE_JG)) {
                     $do_status = $order_item_data['depot_orders_status'] == '4' && isset($order_item_data['depot_orders_prod_status']) && $order_item_data['depot_orders_prod_status'] != '' ? statusNameProduction($order_item_data['depot_orders_prod_status'], false, true) : statusNameShort($order_item_data['depot_orders_status']);
                     if (!is_array($do_status)) {
                         $stock_status = '<a href="?open=depot-order&amp;id=' . $order_item_data['depot_orders_id'] . '&amp;hidemenu=true" ' . 'title="MMO product, current status is ' . $do_status . '" class="red view_webpage">' . $do_status . '</a>';
                     }
                 }
                 break;
             case 'R':
                 $stock_status = $el_link . '<abbr title="Element Stock OK, Ready for Production" class="green">OK</abbr>';
                 break;
             case 'S':
                 $stock_status = $el_link . '<abbr title="Element Stock Need Sourcing" class="red">NS</abbr>';
                 break;
             case 'P':
                 $stock_status = $pr_link . '<abbr title="Use Finished Goods Stock" class="green">FG</abbr>';
                 break;
             case 'D':
                 if (is_null($order_item_data['depot_orders_id'])) {
                     $stock_status = $dp_link . '<abbr title="Use Depot Stock" class="green">DS</abbr>';
                 } else {
                     $stock_status = '<a href="?open=depot-order&amp;id=' . $order_item_data['depot_orders_id'] . '&amp;hidemenu=true" class="green view_webpage">DS</a>';
                 }
                 break;
             case 'W':
                 $stock_status = $el_link . '<abbr title="Product is using Wholesale Element" class="red">WP</abbr>';
                 break;
             default:
                 $stock_status = '<strong class="red">?</strong>';
         }
         $row_data[self::ROW_DATA_STOCK] = $stock_status;
     }
     if ($this->filters_status == 3) {
         $row_data[self::ROW_DATA_PRINTED] = $order_item_data['print_count'] > 0 ? '<img title="Printed ' . $order_item_data['print_count'] . ' time(s)" src="images/icon-tick.png">' : '<img title="Not yet printed" src="images/icon-tick-dis.png">';
         $row_data[self::ROW_DATA_SCANNED] = $order_item_data['print_confirmed'] > 0 ? '<img title="Scanned ' . $order_item_data['print_confirmed'] . ' time(s)" src="images/icon-tick.png">' : '<img title="Not yet scanned" src="images/icon-tick-dis.png">';
     }
     //TODO: DEFINE ACTION BUTTON BASED ON SELECTED TAB
     $row_data[self::ROW_DATA_ACTION] = $action;
     if ($this->filters_status == 4 && in_array($this->filters_sub_status[0], $this->PROD_SUBSTATUS_USE_LINE)) {
         $row_data[self::ROW_DATA_STATUS] = strtoupper(statusNameProduction($order_item_data['prod_status'], true));
     }
     //FILL DATA INTO ROW TEMPLATE
     $row = $this->getRowTemplate($template_row, false, $row_data);
     $result = '';
     if (count($row) > 0) {
         foreach ($row as $c => $r) {
             $result .= '<td class="' . $c . '">' . $r . '</td>';
         }
     }
     return $result;
 }
 $r = tep_db_query($q);
 while ($row = tep_db_fetch_array($r)) {
     $grab_article = false;
     $pid = $row['products_id'];
     $aid = $row['products_articles_id'];
     $is_best_product = $row['status'] == '1';
     $stock = $row['stock'] - $row['booking_active'];
     $stock_and_orders = $stock + $row['ordered'];
     if ($stock < 0) {
         $stock = 0;
     }
     if (!isset($p) || !is_object($p) || $p->id != $pid) {
         $p = new Product($pid);
         $is_in_ltf_col = $p->isLevellingProduct();
     }
     $image_html = $p->displayImage(IMAGE_SIZE_THUMBNAIL_1, IMAGE_SIZE_THUMBNAIL_1);
     $dioh = $p->getDIOH($aid, $stock);
     $dioh2 = $p->getDIOH($aid, $stock + $row['ordered']);
     $dioh_text = $p->displayDIOH($aid, $stock);
     $dioh2_text = $p->displayDIOH($aid, $stock_and_orders);
     $target = $p->getDIOHstockTarget($aid);
     $target_levelling = $p->getLevellingTarget($aid);
     $target_after_levelling = $p->getDIOHstockTargetAfterLevelling($aid);
     $missing = $target - $stock_and_orders;
     if ($missing < 0) {
         $missing = 0;
     }
     $missing_no_refill = $target - $stock;
     if ($missing_no_refill < 0) {
         $missing_no_refill = 0;
     }
function drawProductPriceTable(Product $product, $message = '')
{
    global $class_sp;
    //$supported_sp = array('2', '5', '7', '8');
    //$sp_filer = 'jng_sp_id IN ('.implode(',', $supported_sp).') AND ';
    $show_jng = !SERVER_IS_LOCAL;
    $sp_b2c = $class_sp->retrieveList('use_amvd_logistic = 0');
    $sp_b2b = $class_sp->retrieveList('use_amvd_logistic = 1');
    $total_sp_b2c = count($sp_b2c);
    if ($show_jng) {
        $total_sp_b2c += 1;
    }
    $total_sp_b2b = count($sp_b2b);
    $result = '<div id="price-pid-' . $product->id . '" class="product" ' . 'style="clear:left;float:left;margin-bottom:20px;">' . '<div class="draw-table">' . '<table border="0" cellpadding="0" cellspacing="0">' . '<tr>' . '<th rowspan="2">Product</th>' . '<th colspan="2">Info</th>' . '<th colspan="' . $total_sp_b2c . '">B2C</th>';
    foreach ($sp_b2b as $sp) {
        if ($product->isAddedToSalesPartner($sp['jng_sp_id'])) {
            $btn_addto_catalog = '';
        } else {
            $btn_addto_catalog = '<div style="float:right;"><input ' . 'type="button" class="addtocat" value="add" /></div>';
        }
        $result .= '<th colspan="2">B2B - ' . $sp['package_prefix'] . '</th>';
        /*
        $result .= '<th colspan="2"><div>B2B - ' . 
            $sp['package_prefix'].'</div>' . $btn_addto_catalog . '</th>';
        */
    }
    $result .= $b2b . '</tr>' . '<tr>' . '<th>Name</th>' . '<th class="bold">DEFAULT</th>';
    if ($show_jng) {
        $result .= '<th>JG.DE</th>';
    }
    foreach ($sp_b2c as $sp) {
        $result .= '<th>' . $sp['package_prefix'] . '</th>';
    }
    foreach ($sp_b2b as $sp) {
        $result .= '<th>No Discount</th>';
        $result .= '<th>Discount</th>';
    }
    $jng_id = '0';
    $cogs = $product->getProductCOGSValue();
    $price_uvp = $product->getPriceUVP();
    $price_uvp_text = displayCurrency(CURRENCY_DEFAULT, $price_uvp, false, 2);
    $price_default = $product->getPriceDefault();
    $price_default_text = displayCurrency(CURRENCY_DEFAULT, $price_default, false, 2);
    $price_jng = $product->getPriceSelling($jng_id);
    $price_options = array('Show Discount', 'Hide Discount');
    //, 'No Discount');
    $price_options_combo = '<select name="price_option" style="display:none;">' . '%s</select><span class="notice price_option_none" style="display:none;">' . 'No Discount</span>';
    $price_option_jng = loadComboListFromArray($price_options, null, $product->isPriceSellingUsingDiscount($jng_id) ? 0 : 1, false);
    $sp_type_default = '<input type="hidden" name="sp_type" value="DEF" />';
    $sp_type_b2c = '<input type="hidden" name="sp_type" value="B2C" />';
    $sp_type_b2b_nodisc = '<input type="hidden" name="sp_type" value="B2B-ND" />';
    $sp_type_b2b_disc = '<input type="hidden" name="sp_type" value="B2B-D" />';
    $sp_id_jng = '<input type="hidden" name="sp_id" value="0" />';
    if (SERVER_IS_LOCAL) {
        $class_add = ' readonly';
        $editable = ' readonly="readonly"';
    } else {
        $class_add = '';
        $editable = '';
    }
    $result .= '</tr>' . '<tr class="o">' . '<td class="w200 tac"><div>' . $product->displayImage(IMAGE_SIZE_THUMBNAIL_2, IMAGE_SIZE_THUMBNAIL_2_PORTRAIT) . '</div>' . '<div>' . $product->displayIDAndCode() . '</div>' . '</td>' . '<td class="w150">' . '<div class="cr cr-status">Status</div>' . '<div class="cr cr-uvp">UVP</div>' . '<div class="cr cr-sp">Selling Price</div>' . '<div class="cr cr-factor">Factor</div>' . '<div class="cr cr-disc">Discount</div>' . '<div class="cr cr-option">Price Option</div>' . '<div class="cr cr-preview">Price Preview</div>' . '<div class="cr cr-cogs">COGS</div>' . '<div class="cr cr-profit">Profit</div>' . '<div class="cr cr-margin">Margin</div>' . '<div class="cr cr-premium">Premium</div>' . '</td>' . '<td class="w100 tac">' . '<input type="hidden" name="cogs" value="' . $cogs . '" />' . '<div class="cr cr-status notice">-</div>' . '<div class="cr cr-uvp"><input type="text" name="price-uvp-default" class="w080 tac' . $class_add . '" value="' . $price_uvp . '"' . $editable . ' /></div>' . '<div class="cr cr-sp"><input type="text" name="price-default" class="w080 tac' . $class_add . '" value="' . $price_default . '"' . $editable . ' />' . $sp_type_default . '</div>' . '<div class="cr cr-factor notice">-</div>' . '<div class="cr cr-disc">&nbsp;</div>' . '<div class="cr cr-option notice">-</div>' . '<div class="cr cr-preview">&nbsp;</div>' . '<div class="cr cr-cogs">' . $cogs . '</div>' . '<div class="cr cr-profit">&nbsp;</div>' . '<div class="cr cr-margin">&nbsp;</div>' . '<div class="cr cr-premium">&nbsp;</div>' . '</td>';
    if ($show_jng) {
        //COLUMN J&G
        $result .= '<td class="w100 tac">' . '<div class="cr cr-status">' . $product->displayActiveStatusIcon($jng_id) . '</div>' . '<div class="cr cr-uvp"><input type="text" name="price-uvp" class="w080 tac b2c readonly" value="' . $price_uvp . '" readonly="readonly" />' . $sp_type_b2c . $sp_id_jng . '</div>' . '<div class="cr cr-sp"><input type="text" name="price-selling" class="w080 tac b2c" value="' . $price_jng . '" />' . $sp_type_b2c . $sp_id_jng . '</div>' . '<div class="cr cr-factor notice">-</div>' . '<div class="cr cr-disc">&nbsp;</div>' . '<div class="cr cr-option">' . sprintf($price_options_combo, $price_option_jng) . $sp_id_jng . '</div>' . '<div class="cr cr-preview">&nbsp;</div>' . '<div class="cr cr-cogs notice">' . $cogs . '</div>' . '<div class="cr cr-profit">&nbsp;</div>' . '<div class="cr cr-margin">&nbsp;</div>' . '<div class="cr cr-premium">&nbsp;</div>' . '</td>';
    }
    //COLUMN PER SP (B2C)
    foreach ($sp_b2c as $sp) {
        $result .= '<td class="w100 tac">';
        $result .= '<div class="cr cr-status">' . $product->displayActiveStatusIcon($sp['jng_sp_id']) . '</div>';
        if ($product->isAddedToSalesPartner($sp['jng_sp_id'])) {
            $sp_id = '<input type="hidden" name="sp_id" value="' . $sp['jng_sp_id'] . '" />';
            $price_selling_old = $product->getPriceSellingOld($sp['jng_sp_id']);
            $price_selling = $product->getPriceSelling($sp['jng_sp_id']);
            $price_option_sp = loadComboListFromArray($price_options, null, $product->isPriceSellingUsingDiscount($sp['jng_sp_id']) ? 0 : 1, false);
            if (SERVER_IS_LOCAL) {
                $price_uvp_sp = $price_selling_old > 0 ? $price_selling_old : $price_selling;
                $sp_uvp_class = '';
                $sp_uvp_dis = '';
            } else {
                $price_uvp_sp = $price_uvp;
                $sp_uvp_class = ' readonly';
                $sp_uvp_dis = ' readonly="readonly"';
            }
            $result .= '<div class="cr cr-uvp">' . '<input type="text" name="price-uvp" class="w080 tac b2c' . $sp_uvp_class . '"' . ' value="' . $price_uvp_sp . '" ' . $sp_uvp_dis . ' />' . $sp_id . '</div>';
            $result .= '<div class="cr cr-sp"><input type="text" name="price-selling" class="w080 tac b2c" value="' . $price_selling . '" />' . $sp_type_b2c . $sp_id . '</div>' . '<div class="cr cr-factor notice">-</div>' . '<div class="cr cr-disc">&nbsp;</div>' . '<div class="cr cr-option">' . sprintf($price_options_combo, $price_option_sp) . $sp_id . '</div>' . '<div class="cr cr-preview">&nbsp;</div>' . '<div class="cr cr-cogs notice">' . $cogs . '</div>' . '<div class="cr cr-profit">&nbsp;</div>' . '<div class="cr cr-margin">&nbsp;</div>' . '<div class="cr cr-premium">&nbsp;</div>';
        } else {
            //                $result .= '<span class="red">Not<br />added<br />yet to' .
            //                    '<br />catalog</span><br /><br /><input type="button" ' .
            //                    'value="Add Now" title="Click here to add product now '.
            //                    'to this Sales Partner Catalog" />';
            $result .= '<div class="cr cr-uvp notice">-</div>' . '<div class="cr cr-sp notice">-</div>' . '<div class="cr cr-factor notice">-</div>' . '<div class="cr cr-disc notice">-</div>' . '<div class="cr cr-option notice">-</div>' . '<div class="cr cr-preview notice">Not Added to Catalog</div>' . '<div class="cr cr-cogs notice">-</div>' . '<div class="cr cr-profit notice">-</div>' . '<div class="cr cr-margin notice">-</div>' . '<div class="cr cr-premium notice">-</div>';
        }
        $result .= '</td>';
    }
    //2 COLUMNS PER SP (B2B)
    foreach ($sp_b2b as $sp) {
        $status = $product->displayActiveStatusIcon($sp['jng_sp_id']);
        $status_nodisc = '&nbsp;';
        $status_disc = '&nbsp;';
        $sp_id = '<input type="hidden" name="sp_id" value="' . $sp['jng_sp_id'] . '" />';
        $b2b_disc_status_checked = '';
        $b2b_disc_disabled = '';
        $default_discount = 0.5;
        $selling_price_notsaved_title = '';
        $selling_price_notsaved_class = '';
        if ($product->isAddedToSalesPartner($sp['jng_sp_id'])) {
            $price_selling = $product->getPriceSelling($sp['jng_sp_id']);
            $price_selling_old = $product->getPriceSellingOld($sp['jng_sp_id']);
            if ($price_selling_old == 0) {
                $status_nodisc = $status;
                $price_selling_old = $price_selling;
                $price_selling = round((1 - $default_discount) * $price_selling_old, 2);
            } else {
                $status_disc = $status;
                $b2b_disc_status_checked = ' checked="checked"';
            }
        } else {
            $status_nodisc = $status;
            $status_disc = $status;
            $price_selling_old = $product->getPriceSellingDefaultB2B($price_uvp, $sp['jng_sp_id']);
            $price_selling = round((1 - $default_discount) * $price_selling_old, 2);
            $b2b_disc_disabled = ' disabled="disabled"';
            $selling_price_notsaved_title = ' title="Value is for simulation only and can not be saved because this product is not added to SP catalog"';
            $selling_price_notsaved_class = ' notice';
        }
        $b2b_ds_cb_id = 'po-' . $product->id . '-' . $sp['jng_sp_id'];
        $b2b_disc_status = '<input id="' . $b2b_ds_cb_id . '" type="checkbox" name="price_option"' . $b2b_disc_status_checked . $b2b_disc_disabled . ' /> <label for="' . $b2b_ds_cb_id . '">Active</label>';
        $price_selling_id = 'ps-' . $product->id . '-' . $sp['jng_sp_id'];
        $result .= '<td class="w100 tac">' . '<div class="cr cr-status">' . $status_nodisc . '</div>' . '<div class="cr cr-uvp">' . '<input type="text" name="price-uvp" class="w080 tac b2c readonly"' . ' value="' . $price_uvp . '" readonly="readonly" />' . $sp_id . '</div>' . '<div class="cr cr-sp"><input id="' . $price_selling_id . '-old" type="text" name="price-selling" class="w080 tac b2b-nd' . $selling_price_notsaved_class . '"' . $selling_price_notsaved_title . ' value="' . $price_selling_old . '" />' . $sp_type_b2b_nodisc . $sp_id . '</div>' . '<div class="cr cr-factor">&nbsp;</div>' . '<div class="cr cr-disc notice">-</div>' . '<div class="cr cr-option notice">-</div>' . '<div class="cr cr-preview">&nbsp;</div>' . '<div class="cr cr-cogs notice">' . $cogs . '</div>' . '<div class="cr cr-profit">&nbsp;</div>' . '<div class="cr cr-margin">&nbsp;</div>' . '<div class="cr cr-premium">&nbsp;</div>' . '</td>' . '<td class="w100 tac">' . '<div class="cr cr-status">' . $status_disc . '</div>' . '<div class="cr cr-uvp">' . '<input type="text" name="price-uvp" class="w080 tac b2c readonly"' . ' value="' . $price_uvp . '" readonly="readonly" />' . $sp_id . '</div>' . '<div class="cr cr-sp"><input id="' . $price_selling_id . '" type="text" name="price-selling" class="w080 tac b2b-d' . $selling_price_notsaved_class . '"' . $selling_price_notsaved_title . ' value="' . $price_selling . '" />' . $sp_type_b2b_disc . $sp_id . '</div>' . '<div class="cr cr-factor">&nbsp;</div>' . '<div class="cr cr-disc">&nbsp;</div>' . '<div class="cr cr-option">' . $b2b_disc_status . $sp_id . '</div>' . '<div class="cr cr-preview">&nbsp;</div>' . '<div class="cr cr-cogs notice">' . $cogs . '</div>' . '<div class="cr cr-profit">&nbsp;</div>' . '<div class="cr cr-margin">&nbsp;</div>' . '<div class="cr cr-premium">&nbsp;</div>' . '</td>';
    }
    $result .= '</tr></table></div>';
    $message_block = '';
    $button_style = '';
    if ($message != '') {
        $button_style = ' style="display:none;"';
        $message_block .= '<h3 class="green">' . $message . '</h3>';
    }
    $result .= '<div class="tar" style="margin-top:5px;"><input type="button"' . ' class="w400 button" name="save-price" value="Save Product Price" ' . $button_style . '/>' . $message_block . '</div>' . '</div>';
    return $result;
}
 /**
  * For handling submitted POST
  * @global array $session_userinfo
  * @param array $post_vars
  */
 public function postProcess($post_vars)
 {
     global $session_userinfo;
     $result = array();
     if ($post_vars['me_action'] == 'SEARCH') {
         $type = $post_vars['type'];
         $jng_sp_id = $post_vars['jng_sp_id'];
         //another strange case, in live datepicker filter is always given as \'datevalue\' instead of 'datevalue'
         //still cant find the root cause (and it's ok in local dev), so for quickwin workaround we simple replace
         //the \' value into ' with below update (sahat 11.02.2014)
         //$post_filters = explode("|", $post_vars['post_filters']);
         $post_filters = explode("|", str_replace('\\\'', "'", $post_vars['post_filters']));
         $post_sorts = explode("|", $post_vars['post_sorts']);
         $filters = array();
         foreach ($post_filters as $f) {
             $f_temp = explode('-', $f);
             $field = $f_temp[0];
             unset($f_temp[0]);
             $value = implode('-', $f_temp);
             //explode to array for input on field $multivalue_fields which allowed multivalue separated by $multivalue_separator
             if (in_array($field, $this->multivalue_fields)) {
                 $mv_temp = explode(current($this->multivalue_separator), $value);
                 if (is_array($mv_temp) && $mv_temp > 0) {
                     foreach ($mv_temp as $mv) {
                         $mv = trim($mv);
                         if (!isset($filters[$field]) || !in_array($mv, $filters[$field])) {
                             $filters[$field][] = $mv;
                         }
                     }
                 } else {
                     $filters[$field][] = $value;
                 }
             } else {
                 $filters[$field][] = $value;
             }
         }
         $sorts = array();
         foreach ($post_sorts as $s) {
             list($field, $value) = explode("-", $s);
             $sorts[$field][] = $value;
         }
         $query = $this->constructQuery($jng_sp_id, $filters, $sorts);
         //die($query);
         $dbq = tep_db_query($query);
         $result = '';
         $products_ids = array();
         $total_stock = 0;
         $total_stock_value = 0;
         $total_margin = 0;
         $total_sold = 0;
         $total_rets = 0;
         $total_sales = 0;
         $total_vc = 0;
         $total_sold_l30d = 0;
         $total_sold_l60d = 0;
         $total_sold_l90d = 0;
         $total_sales_l30d = 0;
         $total_sales_l60d = 0;
         $total_sales_l90d = 0;
         $display_spot = '';
         while ($r = tep_db_fetch_array($dbq)) {
             $products_ids[] = $r['products_id'];
             $total_stock += $r['hh_stock'];
             $total_stock_value += $r['hh_stock_value'];
             $total_margin += $r['margin'];
             $total_sold += $r['total_sold'];
             $total_rets += $r['total_returned'];
             $total_sales += $r['total_sales'];
             $vc += $r['vc_now'];
             //$total_vc += $r['total_vc'];
             $total_vc += $r['vc_total'];
             $total_sold_l30d += $r['sold_monthly_1'];
             $total_sold_l60d += $r['sold_monthly_2'];
             $total_sold_l90d += $r['sold_monthly_3'];
             $total_sales_l30d += $r['sales_monthly_1'];
             $total_sales_l60d += $r['sales_monthly_2'];
             $total_sales_l90d += $r['sales_monthly_3'];
         }
         $jng_nodata = '<span class="notice">N/A&nbsp;for&nbsp;J&amp;G</span>';
         $returned_rate = number_format($total_sold > 0 ? $total_rets / $total_sold * 100 : 0, 1);
         $n_products_ids = count($products_ids);
         $result['type'] = $type;
         $result['spid'] = $jng_sp_id;
         $result['avg_margin'] = ($n_products_ids > 0 ? number_format($total_margin / $n_products_ids, 1) : 0) . '%';
         $result['total'] = $n_products_ids;
         $result['total_stock'] = $total_stock;
         $result['total_stock_value'] = displayCurrency(CURRENCY_DEFAULT, convertCurrency($total_stock_value, CURRENCY_CODE_EURO, CURRENCY_DEFAULT));
         $result['total_sold'] = $jng_sp_id == '0' ? $jng_nodata : $total_sold;
         $result['total_rets'] = $jng_sp_id == '0' ? $jng_nodata : $total_rets . " ({$returned_rate}%)";
         $result['total_sales'] = $jng_sp_id == '0' ? $jng_nodata : displayCurrency(DEFAULT_CURRENCY, $total_sales);
         $result['vc'] = $jng_sp_id == '0' ? $jng_nodata : number_format($vc, 2);
         //$result['total_vc'] = number_format($total_vc, 2);
         $result['vc_total'] = $jng_sp_id == '0' ? $jng_nodata : number_format($total_vc, 2);
         $result['total_sales_l30d'] = displayCurrency(DEFAULT_CURRENCY, $total_sales_l30d);
         $result['total_sales_l60d'] = displayCurrency(DEFAULT_CURRENCY, $total_sales_l60d);
         $result['total_sales_l90d'] = displayCurrency(DEFAULT_CURRENCY, $total_sales_l90d);
         $result['total_sold_l30d'] = $total_sold_l30d;
         $result['total_sold_l60d'] = $total_sold_l60d;
         $result['total_sold_l90d'] = $total_sold_l90d;
         $result['products_ids'] = implode(',', $products_ids);
     } elseif ($post_vars['me_action'] == 'DISPLAY') {
         use_class('products_minierp');
         use_class('minierp_users');
         use_class('Product');
         $class_pm = new products_minierp();
         $class_mu = new minierp_users();
         $jng_sp_id = $post_vars['jng_sp_id'];
         $type = $post_vars['type'];
         $products_id = $post_vars['products_id'];
         $is_killed = $post_vars['is_killed'];
         $is_sp_not_yet_added = $post_vars['is_sp_not_yet_added'];
         $added_post_vars = array('is_killed' => $is_killed, 'is_sp_not_yet_added' => $is_sp_not_yet_added);
         $display_type = $post_vars['display_type'];
         $row_number = $post_vars['row_number'];
         $showing_id = $post_vars['showing_id'];
         $obj_product = new Product($products_id);
         $display_res = $this->retrieveDataForDisplay($jng_sp_id, $products_id, $added_post_vars, $display_type);
         $res = $display_res[0];
         $img_size = $display_type == 'thumbnail' ? IMAGE_SIZE_THUMBNAIL_2 : IMAGE_SIZE_THUMBNAIL_1;
         //SHOW PURE IMAGE FOR SP THAT USED IT AS MAIN IMAGE
         if (in_array($jng_sp_id, $this->sp_use_pure_image)) {
             $obj_product->setDisplayImage(Product::IMAGE_TYPE_ZALANDO);
         } else {
             if (in_array($jng_sp_id, $this->sp_use_clear_image)) {
                 $obj_product->setDisplayImage(Product::IMAGE_TYPE_AMAZON);
             }
         }
         //$products_image = webImageWithDetailLinkStars($image_used, $img_size, $img_size, 'Product '.$products_id, 'img-border', 'View Larger Image', IMAGE_SIZE_BIG_1, '', $res['stars'], 3, '', '', $res['products_brand_id']);
         $products_image = $obj_product->displayImage($img_size, $img_size);
         $position_padding = $display_type == 'thumbnail' ? '2px 0 0 15px;' : '';
         $products_image = webImageAddPosition($row_number, $products_image, $position_padding);
         $products_complexity = productComplexityName($res['complexity']);
         $products_stars = drawStars($res['stars']);
         $products_is_watched = $class_mu->isOnWatchlist($session_userinfo['id'], $products_id);
         $resultsdt = array();
         if ($display_type == 'table' || $type == 'displaytooltip') {
             if ($type == 'thumbnail_tooltip') {
                 //HTML Version result
                 $sales_partner_id = $jng_sp_id == 'allsp' ? '0' : $jng_sp_id;
                 //TODO: seperate B2C and B2b calculation, or even better is if
                 //      we can calculate it by the object directly
                 $price = $obj_product->getPriceSelling($sales_partner_id);
                 $net_price = Product::calculateNetPrice($price, VAT);
                 $cogs = $obj_product->getProductCOGSValue();
                 $profit = Product::calculateProfit($net_price, $cogs);
                 $margin = Product::calculateMargin($profit, $net_price);
                 $jng_nodata = '<span class="notice">N/A for J&amp;G</span>';
                 $infos = array();
                 $infos[] = $obj_product->displayIDAndCode();
                 $infos[] = $res['products_name'];
                 if ($res['hh_stock'] > 0) {
                     $infos[] = '<strong class="green">Depot Stock = ' . $res['hh_stock'] . '</strong>';
                 } else {
                     $infos[] = '<strong>Depot Stock = 0</strong>';
                 }
                 $infos[] = 'Complexity = ' . $products_complexity;
                 if ($res['sample_created'] == '1') {
                     $infos[] = '<span class="green">Sample order created</span>';
                 } else {
                     $infos[] = '<span class="notice">No sample order created</span>';
                 }
                 if ($jng_sp_id == '0') {
                     $total_sold = $jng_nodata;
                     $return_info = $jng_nodata;
                     $qty_sold = $jng_nodata;
                 } else {
                     $returned_rate = number_format($res['returned_rate'], 1);
                     $sales_monthly = number_format($res['sales_monthly'], 1);
                     $sales_weekly = number_format($res['sales_weekly'], 1);
                     $total_sold = $res['total_sold'];
                     $return_info = $res['total_returned'] . ' (' . $returned_rate . '%)';
                     $qty_sold = "per Week: {$sales_weekly} &sdot; per Month: {$sales_monthly}";
                 }
                 $tooltip = '<div class="draw-table"><table border="0" cellpadding="0" cellspacing="0">';
                 $tooltip .= '<tr class="o"><td class="w200 bold">Brand</td><td class="w300 bold">' . $res['brand_name'] . '</td></tr>';
                 $tooltip .= '<tr class="e"><td>Info</td><td>&bull; ' . implode('<br />&bull; ', $infos) . '</td></tr>';
                 $tooltip .= '<tr class="o"><td>Price Preview</td><td>' . $obj_product->displayPricePreview($sales_partner_id) . '</td></tr>';
                 $tooltip .= '<tr class="e"><td>Margin in %</td><td>' . $obj_product->displayMargin($price, $margin) . '</td></tr>';
                 $tooltip .= '<tr class="o"><td>Age JG (finalized)</td><td>' . $res['jng_products_age'] . ' days</td></tr>';
                 $tooltip .= '<tr class="e"><td>Age (selected SP filter)</td><td>' . $res['products_age'] . ' days</td></tr>';
                 $tooltip .= '<tr class="o"><td>Total Sold (excl. JG)</td><td>' . $total_sold . '</td></tr>';
                 $tooltip .= '<tr class="e"><td>Total Returns (excl. JG)</td><td>' . $return_info . '</td></tr>';
                 $tooltip .= '<tr class="o"><td>Pieces Sold</td><td>' . str_replace('align="center"', 'align="left"', $obj_product->displayRecentSoldTable()) . '</div></td></tr>';
                 $tooltip .= '<tr class="e"><td>Qty. Sold (excl. JG)</td><td>' . $qty_sold . '</td></tr>';
                 $tooltip .= '</table></div>';
                 $ajaxResult = array();
                 $ajaxResult['type'] = $type;
                 $ajaxResult['spid'] = $jng_sp_id;
                 $ajaxResult['products_id'] = $products_id;
                 $ajaxResult['tooltip'] = $tooltip;
                 $ajaxResult['rownumber'] = $row_number;
                 $ajaxResult['showingid'] = $showing_id;
                 ajaxReturn($ajaxResult);
             } else {
                 $sales_partner_id = $jng_sp_id == 'allsp' ? '0' : $jng_sp_id;
                 $price = $obj_product->getPriceSelling($sales_partner_id);
                 $net_price = Product::calculateNetPrice($price, VAT);
                 $cogs = $obj_product->getProductCOGSValue();
                 $profit = Product::calculateProfit($net_price, $cogs);
                 $margin = Product::calculateMargin($profit, $net_price);
                 $material_expenses = displayCurrency(DEFAULT_CURRENCY, convertCurrency($res['material_expenses'], 'EUR', DEFAULT_CURRENCY), false);
                 $products_price = displayCurrency(DEFAULT_CURRENCY, $res['products_price'], false);
                 $products_price_old = displayCurrency(DEFAULT_CURRENCY, $res['products_price_old'], false);
                 $products_created = date('d-M-Y', strtotime($res['products_date_added']));
                 $vc_now = number_format($res['vc_now'], 2);
                 $total_vc = number_format($res['vc_total'], 2);
                 $vc_percent = number_format($res['vc_percent'], 1);
                 //$margin = $res['margin'];
                 //$margin = '<span class="'.(($class_pm->priceMargindIsGood($res['products_price'], $margin)) ? 'green' : 'red') . '">' .
                 //    number_format($margin, 1) . '%</span>';
                 $margin = $obj_product->displayMargin($price, $margin);
                 $returned_rate = number_format($res['returned_rate'], 1);
                 $discount = number_format($res['products_discount'], 2);
                 $total_sales = number_format($res['total_sales'], 2);
                 $sales_monthly = number_format($res['sales_monthly'], 1);
                 $sales_weekly = number_format($res['sales_weekly'], 1);
                 $jng_nodata = '<span class="notice">N/A' . ($type == 'displaytooltip' ? '&nbsp;' : '<br />') . 'for&nbsp;J&amp;G</span>';
                 //0-4
                 $resultsdt[] = $products_image;
                 $resultsdt[] = $products_id;
                 $resultsdt[] = $res['products_model'];
                 $resultsdt[] = $res['products_name'];
                 //$resultsdt[] = $class_pm->displayProductName($products_id);
                 $resultsdt[] = $products_price_old;
                 //5-9
                 $resultsdt[] = $products_price;
                 $resultsdt[] = $discount;
                 $resultsdt[] = $jng_sp_id == '0' ? $jng_nodata : $vc_now;
                 $resultsdt[] = $jng_sp_id == '0' ? $jng_nodata : $vc_percent;
                 $resultsdt[] = $margin;
                 //10-14
                 $resultsdt[] = $res['products_age'];
                 $resultsdt[] = $jng_sp_id == '0' ? $jng_nodata : $res['total_sold'];
                 $resultsdt[] = $jng_sp_id == '0' ? $jng_nodata : $total_vc;
                 $resultsdt[] = $res['total_returned'];
                 $resultsdt[] = $jng_sp_id == '0' ? $jng_nodata : $returned_rate;
                 //15-19
                 $resultsdt[] = $jng_sp_id == '0' ? $jng_nodata : $total_sales;
                 $resultsdt[] = $res['sold_monthly_1'];
                 $resultsdt[] = $res['sold_monthly_2'];
                 $resultsdt[] = $res['sold_monthly_3'];
                 $resultsdt[] = $jng_sp_id == '0' ? $jng_nodata : $sales_weekly;
                 //20-24
                 $resultsdt[] = $jng_sp_id == '0' ? $jng_nodata : $sales_monthly;
                 $resultsdt[] = $res['brand_name'];
                 $resultsdt[] = $res['kill_status'];
                 $resultsdt[] = $products_created;
                 $resultsdt[] = $res['hh_stock'];
                 //25-28
                 $resultsdt[] = $products_complexity;
                 $resultsdt[] = $products_stars;
                 $resultsdt[] = $products_is_watched;
                 $resultsdt[] = $res['sample_created'];
                 //29
                 $resultsdt[] = $res['jng_products_age'];
                 $resultsdt[] = $material_expenses;
                 $resultsdt[] = $res['products_length'];
             }
         } elseif ($display_type == 'thumbnail') {
             //0-4
             $resultsdt[] = $products_image;
             $resultsdt[] = $products_id;
             $resultsdt[] = $res['products_model'];
             $resultsdt[] = $products_stars;
             $resultsdt[] = $products_is_watched;
             //5
             $resultsdt[] = $res['sample_created'];
         }
         $result['type'] = $type;
         $result['spid'] = $jng_sp_id;
         $result['result'] = implode($this->result_separator, $resultsdt);
         $result['rownumber'] = $row_number;
         $result['showingid'] = $showing_id;
     }
     ajaxReturn($result);
 }
     $imgwidth = '';
     $imgheight = '';
 }
 if (strlen($product_entry) == 13) {
     $obj_product = Product::loadObjectFromEAN($product_entry);
 } else {
     $obj_product = Product::loadObjectFromProductCode($product_entry);
     if ($obj_product === false) {
         $obj_product = new Product($product_entry);
     }
 }
 $result = '';
 if ($obj_product === false) {
     $result .= '<h3 class="red">Product <strong>' . $product_entry . '</strong> not found!</h3>';
 } else {
     $result .= '<div style="float:left;">' . $obj_product->displayImage(IMAGE_SIZE_THUMBNAIL_1, IMAGE_SIZE_THUMBNAIL_1_PORTRAIT) . '</div><div style="margin-left:120px;">';
     $attributes = ProductAttribute::getOldStylesFunction()->getProductStyles($obj_product->id);
     $total_images = 0;
     foreach ($attributes[ProductAttribute::GROUP_ID_PACKAGING] as $attribute_id => $attribute_name) {
         $obj_pa = new ProductAttribute($attribute_id);
         foreach ($obj_pa->getAttachmentsAsObject()->getFilesAsArray() as $img_index => $img_file) {
             $total_images++;
             $result .= '<div style="margin-bottom:10px;">' . $obj_pa->getAttachmentsAsObject()->displayImageFile($img_index, $imgwidth, $imgheight) . '</div>';
         }
     }
     if ($total_images == 0) {
         $result .= ERROR_MESSAGE_NOIMAGE;
     }
     $result .= '</div>';
 }
 echo utf8_encode($result);
     echo "REM-{$pid}";
     exit;
 } elseif ($_POST['me_action'] == 'LOADPRODUCT') {
     $pid = tep_db_prepare_input($_POST['pid']);
     $pos = tep_db_prepare_input($_POST['pos']) + 1;
     $obj_product = new Product($pid);
     $product = $class_pm->retrieveDetail($pid, 'p,pd,pl,sp');
     $product_sp = $class_jc->retrieveDetail(null, $jng_sp_id, $pid);
     $added = is_array($product_sp) && isset($product_sp['active_status']);
     $stock = $class_pm->stockRetrieve(WAREHOUSE_ID_PRODUCTS_HAMBURG, $pid);
     $cols = array();
     foreach ($header as $hk => $hv) {
         $value = '';
         switch ($hk) {
             case 'img':
                 $value .= webImageAddPosition($pos, $obj_product->displayImage(IMAGE_SIZE_THUMBNAIL_2, IMAGE_SIZE_THUMBNAIL_2_PORTRAIT));
                 break;
             case 'nm w300':
                 $value .= $product['p']['products_brand_name'];
                 $value .= '<br />' . $obj_product->displayIDAndCode();
                 $value .= '<br />' . $product['pd']['2']['products_name'];
                 $value .= '<br /><br /><a href="?open=products-price&amp;pids=' . $pid . '&amp;hidemenu=true&amp;hidecopyurl=true"';
                 $value .= ' class="bold view_webpage">&raquo; Click here to manage price details!</a>';
                 break;
             case 'ps w150':
                 $value .= $obj_product->displayRecentSoldTable();
                 $value .= '<br /><br />';
                 $value .= $obj_product->displayYearlySoldTable();
                 break;
             case 'st w100':
                 $value .= strval($stock);
    return $return;
}
if (isset($_POST['me_action']) && $_POST['me_action'] == 'PROCESS') {
    $spid = strtoupper(tep_db_prepare_input($_POST['spid']));
    $products_id = tep_db_prepare_input($_POST['pid']);
    $week_start = str_ireplace('week', '-', tep_db_prepare_input($_POST['start_week']));
    $week_end = str_ireplace('week', '-', tep_db_prepare_input($_POST['end_week']));
    $p = $class_pm->retrieveDetail($products_id, 'p');
    $not_available_text = '<span class="notice">N/A</span>';
    $result = '<div id="box-' . $products_id . '" class="float-left ui-corner-all" style="margin:10px 10px 0 0; padding:10px; border:solid 1px #ccc;">';
    if ($p['p'] !== false) {
        //Get Product Info
        $product = new Product($products_id);
        $product_info = "{$product->id}/{$product->code}";
        $result .= ' <div class="tac">';
        $result .= $product->displayImage(IMAGE_SIZE_THUMBNAIL_2, IMAGE_SIZE_THUMBNAIL_2);
        $link_product = '<a href="?open=product-detail&amp;hidemenu=true&amp;products_id=' . $products_id . '" class="view_webpage"> ' . $product_info . '</a>';
        $result .= '  <br/>' . $link_product;
        if ($product->isAddedToSalesPartner($spid) || $spid == 'ALL') {
            $cogs = $product->getProductCOGSValue();
            //Get price selling
            if ($spid == 'ALL') {
                $price_selling = $product->getPriceDefault();
            } else {
                $price_selling = $product->getPriceSelling($spid);
            }
            //Get total sold
            $total_sold = $not_available_text;
            if ($spid > 0 || $spid == 'ALL') {
                $total_sold = $class_jc->getTotalSold($products_id, $spid);
            }