$res = array();
 $res = $class_ps->retrieveDataForDisplay($sp_id, $pids[0]);
 //echo "<pre>";var_dump($res);die();
 $res = $res[0];
 $products_image = webImageWithDetailLink($res['products_image'], IMAGE_SIZE_THUMBNAIL_1, IMAGE_SIZE_THUMBNAIL_1, 'Product ' . $pids[0], 'img-border');
 $products_price_old = displayCurrency('', $res['products_price_old']);
 $products_price = displayCurrency('', $res['products_price']);
 $discount = number_format($res['products_discount'], 2);
 $products_created = date('d-M-Y', strtotime($res['products_date_added']));
 $returned_rate = number_format($res['returned_rate'], 2);
 $total_sales = number_format($res['total_sales'], 2);
 $vc_now = number_format($res['vc_now'], 2);
 $total_vc = number_format($res['total_vc'], 2);
 $vc_percent = number_format($res['vc_percent'], 2);
 $margin = $res['margin'];
 $margin = '<span class="' . ($class_pm->priceMargindIsGood($res['products_price'], $margin) ? 'green' : 'red') . '">' . number_format($margin, 1) . '%</span>';
 $sales_monthly = number_format($res['sales_monthly'], 1);
 $sales_weekly = number_format($res['sales_weekly'], 1);
 $products_complexity = productComplexityName($res['complexity']);
 $products_stars = $class_pm->getDisplayStars('', $res['stars']);
 $t = array();
 $t['no'] = '<div>' . $n . '</div>';
 $t['image'] = '<div>' . $products_image . '</div>';
 $t['info'] = '<div><a href="?open=product-detail&products_id=' . $res['products_id'] . '" target="_blank">';
 $t['info'] .= $res['products_id'] . ' / ' . $res['products_model'] . '</a><br/>' . $res['products_name'] . '<br/>' . $products_stars . '<br/><br/>&raquo;&nbsp;';
 $hh_stock = $res['hh_stock'] > 0 ? $res['hh_stock'] : '0';
 $t['info'] .= '<strong class="' . ($res['hh_stock'] > 0 ? 'green' : '') . '">Depot HH Stock = ' . $hh_stock . '</strong>';
 $t['info'] .= '<br/>&raquo;&nbsp;Complexity = ' . $products_complexity . '</div>';
 $t['created'] = '<div>' . $products_created . '</div>';
 $t['priceold'] = '<div>' . $products_price_old . '</div>';
 $t['price'] = '<div>' . $products_price . '</div>';
     $q .= " LEFT JOIN jng_sp_catalog {$alias}";
     $q .= "     ON {$alias}.jng_sp_id={$jng_sp_id} AND {$alias}.products_id=p.products_id";
 }
 $q .= " WHERE p.products_id = {$pid}";
 $r = tep_db_query($q);
 $no_old_price = '<span style="color:#ababab;">No Old Price</span>';
 while ($row = tep_db_fetch_array($r)) {
     $price_old = round($product['p']['products_price_old'], 2);
     $price = round($product['p']['products_price'], 2);
     $net_price = product::calculateNetPrice($price, VAT);
     $mat_expense = $product['p']['material_expenses'];
     $cogs = product::calculateCOGS($mat_expense, $product['p']['complexity']);
     $profit = product::calculateProfit($net_price, $cogs);
     $profit_old = product::calculateProfit($net_price, $mat_expense);
     $margin = product::calculateMargin($profit, $net_price);
     $margin_is_good = $class_pm->priceMargindIsGood($price, $margin);
     $margin_old = product::calculateMargin($profit_old, $net_price);
     $margin_old_is_good = $class_pm->priceMargindIsGood($price, $margin_old);
     $premium = $class_pm->calcPremiumPrice($price, $cogs);
     $premium_old = $class_pm->calcPremiumPrice($price, $mat_expense);
     $purchase_price = product::calculatePurchasePrice($cogs);
     $purchase_price_old = product::calculatePurchasePrice($mat_expense);
     $is_active = $row['products_status'] == '1';
     $status_price = $row['jng_status_price'];
     $jng_icon_eye = $is_active ? getIconEyePricesBasedOnRules($status_price, 'jg') : array();
     $jng = '<img src="/images/icon-tick' . ($is_active ? '' : '-dis') . '.png" class="activation" />';
     $jng .= '<br /><br />';
     if ($row['jng_price_old'] > 0) {
         $jng_price_old = '<span class="price-old">' . displayCurrency('EUR', $row['jng_price_old']) . '</span>';
         $jng .= $jng_price_old . $jng_icon_eye['price_old'];
     } else {
 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;
 }
 function manageOrderList($jng_sp_id, $status, $ean_list = null, $date_start = null, $date_end = null, $brand_id = null, $cat_id = null, $orders_no = '')
 {
     global $STOCKLESS_ELEMENTS_CATEGORY, $PROD_SUBSTATUS_USE_LINE;
     $USE_ORDER_FILTER_TO_ALLOW_PRINTING_PI = false;
     $show_stock_status = $status == '1' || $status == '2' || $status == '3' || $status == '4' || $status == '8';
     $orders_items = $this->retrieveOrdersItems($jng_sp_id, $status, $ean_list, $date_start, $date_end, $brand_id, $cat_id, $orders_no);
     list($status, $sub_status) = explode('-', $status);
     if ($status == '10') {
         $cancel = $this->retrieveCancelList($jng_sp_id);
         if (count($cancel) > 0) {
             foreach ($cancel as $c) {
                 $orders_items[] = $c;
             }
         }
     }
     $orders = array();
     $result = $this->manageOrderList_drawFilter($jng_sp_id, $ean_list, $date_start, $date_end, $brand_id, $cat_id, $orders_no);
     if ($status == '1') {
         //Check if there are orders below the shipping window
         $orders_hidden_by_shipping_window = $this->statusCounterQuery($jng_sp_id, $status, true, $ean_list, $date_start, $date_end, $brand_id, '', '', '', null, $orders_no);
         if ($orders_hidden_by_shipping_window > 0) {
             $result .= '<h3 class="red">' . $orders_hidden_by_shipping_window . ' rows are hidden due to their long Shipping Window</h3>';
         }
     }
     if ($status == '10') {
         $result .= '<h2>Cancelled Products <a href="?open=sp-orders-cancel&amp;hidemenu=true" class="view_webpage" title="Cancel Products"></a><input type="button" id="btn_canceladd" name="canceladd" value="Add" /></h2>';
     }
     if (count($orders_items) > 0) {
         $class_pm = new products_minierp();
         $header = array();
         //$header['d'] = (($status < 2) OR ($status > 7)) ? 'Date' : 'Lead Time';
         $header['d'] = $status > 9 ? 'Date' : 'Lead Time';
         if ($status <= 9) {
             $header['d2'] = 'Cycle Time';
         }
         //            $header['d2'] = ($status=='10') ? 'Cancel' : '<abbr title="Reported Shipping Date">RSD</abbr>';
         //if (!(($status < 2) OR ($status > 7))) $header['d2'] = 'Started Date';
         $header['l'] = 'SP';
         $header['c'] = 'Customer / Order No';
         $header['o'] = 'Order ID';
         $header['a'] = 'Article No';
         $header['p'] = 'Price';
         $header['q'] = 'Qty';
         $header['m'] = 'Margin';
         if ($show_stock_status) {
             $header['s'] = $status == '8' ? 'Status' : 'Stock';
         }
         if ($status == '3') {
             $header['pc1'] = '<abbr title="PI has been sent to PRINTER by MC">P</abbr>';
             $header['pc2'] = '<abbr title="PI has been SCANNED for EAN label in MC">S</abbr>';
         }
         $sub_status = trim($sub_status);
         $sub_prod_show_line_only = in_array($sub_status[0], $PROD_SUBSTATUS_USE_LINE);
         if ($status == '4' && $sub_prod_show_line_only) {
             $header['g'] = 'Status';
         }
         $header['t'] = 'Action';
         //$orders[] = $o;
         $orders_vorkasse_unpaid = array();
         $orders_sent_unconfirmed = array();
         $show_btn_inprod = false;
         $show_btn_insrcn = false;
         if ($status == '5' || $status == '14') {
             //Query Package for Finish and Return Products
             $package_type = $status == '14' ? 'R' : null;
             use_class('jng_sp_packages');
             $class_jp = new jng_sp_packages();
             $usable_packages = $class_jp->getUsablePackages($jng_sp_id, $package_type);
             $packages_exist = count($usable_packages) > 0;
         }
         $timestamp = date('Y-m-d H:i:s');
         $order_pi_print_count = array();
         $order_pi_ready = array();
         $order_pi_collection = array();
         $order_pi_unscanned = array();
         foreach ($orders_items as $oiid => $row) {
             $oid = $row['jng_sp_orders_id'];
             $products_id = $row['products_id'];
             $articles_id = $row['products_articles_id'];
             $order_pi_print_count[$oid][$oiid] = $row['print_count'];
             $order_pi_unscanned[$oid][$oiid] = $row['print_confirmed'];
             $obj_product = new Product($products_id);
             if (!isset($order_pi_collection[$oid])) {
                 $order_pi_ready[$oid] = false;
                 $order_pi_collection[$oid] = array();
             }
             $order_pi_collection[$oid][] = $row['jng_sp_orders_items_id'];
             if (count($order_pi_collection[$oid]) == $row['order_item_total']) {
                 $order_pi_ready[$oid] = true;
                 if (orderItemHaveStatus($oid, 10, 'SP')) {
                     $order_pi_ready[$oid] = false;
                 }
             }
             /* 
                             ### CHANGED THIS TO USING invoice balance, SINCE PREPAYMENT PREAUTH COULD ALSO PROCESSED WHEN 'U-Underpaid' BUT THEN THERES CANCEL CONFIRMED AND MAKE STATUS BECOME 'P-Paid OR O-Overpaid' ###
                             $order_vorkasse_unpaid = (strtoupper($row['payment_method'])==strtoupper(PAYMENT_METHOD_PREPAYMENT) && $row['invoice_complete_status']!='P' && $row['invoice_complete_status']!='O' && $row['invoice_complete_status']!='1');
             */
             $order_vorkasse_unpaid = strtoupper($row['payment_method']) == strtoupper(PAYMENT_METHOD_PREPAYMENT) && !conditionPrepaymentIsPaid($row);
             $order_sent_unconfirmed = $row['status'] == '9' && $row['confirm_delivery'] == '0';
             $o = array();
             $order_date = strtotime($row['order_date']);
             /*
                             $date_used = ($status < 3) ? strtotime($row['status_date']) : strtotime($row['prod_target_in']);
                             if (($status < 2) OR ($status > 7)) {
                $value_date = date('d-M-y', $order_date);
                             } else {
                $value_date = displayLeadTime($row['prod_target_in'], $date_used);
                             }
                             $o['d'] = $value_date;
             */
             $o['d'] = $order_vorkasse_unpaid || $status > 9 ? date('d-M-y', $order_date) : displayLeadTime($row['leadtime_start_date'], strtotime($row['leadtime_start_date']));
             if ($status <= 9 && !$order_vorkasse_unpaid) {
                 $previous_moved_date = $status == 4 ? $row['status_date_prod'] : $row['status_date'];
                 $o['d2'] = displayCycleTime($previous_moved_date);
             }
             //                if($status=='10') {
             //                    $o['d2'] = date('d-M-y', strtotime($row['status_date']));
             //                } else {
             //                    $o['d2'] = $this->reportedShippingDate($order_date, $status, $row['delivery_time'], $row['delivery_replacement_time']);
             //                    if($row['service_code']!='' && $row['service_code']!='ZRE') {
             //                        $title = 'Use Service Code: '.$row['service_code'];
             //                        $new = '<div style="border-bottom:1px solid #f00;text-decoration:blink;cursor:pointer;color:#f00;" title="'.$title.'" onclick="alert(\''.$title.'\');" ';
             //                        $old = '<div ';
             //                        $o['d2'] = str_replace($old, $new, $o['d2']);
             //                    }
             //                }
             //                if (!(($status < 2) OR ($status > 7))) $o['d2'] = date('d-M-y', $date_used);
             $o['l'] = $row['package_prefix'];
             $cust = '<a href="?open=sp-customer&amp;id=' . $row['jng_sp_customers_id'] . '&amp;hidemenu=true" class="view_webpage" >' . $row['customer_name'] . '</a>';
             $crown_img_col = array('V' => 'vip', 'B' => 'black');
             if ($row['list_type'] != '' && array_key_exists($row['list_type'], $crown_img_col)) {
                 $crown_img_title = array('V' => 'VIP Customer', 'B' => 'Blacklist Customer');
                 $crown_img = '<a href="?open=sp-customers-special-detail&amp;id=' . $row['jng_sp_customers_id'] . '&amp;hidemenu=true" class="view_webpage">';
                 $crown_img .= '<img src="images/list-' . $crown_img_col[$row['list_type']] . '.gif" title="' . $crown_img_title[$row['list_type']] . '" />';
                 $crown_img .= '</a> ';
                 $cust = $crown_img . $cust;
             }
             $cust .= ' <sup>' . $row['customers_order_count'] . '</sup>';
             $jng_sp_orders_items_id = 'SP-' . $row['jng_sp_orders_items_id'];
             $jng_sp_orders_items_id = '<a href="?open=sp-order-history&amp;oi_id=' . $row['jng_sp_orders_items_id'] . '&amp;hidemenu=true" class="view_webpage">' . $jng_sp_orders_items_id . '</a>';
             $order_no = $row['order_id'];
             if ($order_no == '') {
                 $order_no = 'J&amp;G ID: ' . $row['jng_sp_orders_id'];
             }
             $order_no = '<a href="?open=customer-care-order-detail&amp;source=SP&amp;id=' . $row['jng_sp_orders_id'] . '&amp;hidemenu=true" class="view_webpage">' . $order_no . '</a>';
             if ($row['order_item_total'] > 1) {
                 $jng_sp_orders_items_id .= ' <sup>' . $row['order_item_count'] . '/' . $row['order_item_total'] . '</sup>';
             }
             if ($row['cod_costs'] > 0) {
                 $order_no = '<img src="images/list-cod.gif" title="COD Method" /> ' . $order_no;
             }
             $o['c'] = $cust . '<br /><small>order no:</small> ' . $order_no;
             $o['o'] = $jng_sp_orders_items_id;
             //$diamond_icon = ($obj_product->brand_id == 14) ? drawDiamondIcon('Diamond Product', ' ') : '';
             $diamond_icon = $obj_product->isUsingDiamond() ? drawDiamondIcon('Diamond Product', ' ') : '';
             $gold_icon = drawGoldIcon($obj_product->metal_stamp_code, $obj_product->metal_stamp_info, '', ' ');
             $article = '<div><a href="?open=product-detail&amp;products_id=' . $products_id . '" target="_blank" title="View Product Detail">' . $row['article_number'] . '</a></div>';
             $icons = $gold_icon . $diamond_icon;
             $pimg = webImageSource($row['products_image'], '500');
             if ($pimg != '') {
                 $thumb = '<div class="thumb" thumbid="' . "{$products_id}-{$articles_id}-{$jng_sp_id}" . '"><a href="' . $pimg . '" class="view_image" title="Click to view larger image">' . webImage($row['products_image'], '80', '80', '', 'img-border img-padding') . '</a></div>';
                 $article = $thumb . $article;
             }
             $o['a'] = drawTableArticleInfoWithIcons($article, $icons);
             $o['p'] = $row['price'];
             $qty = intval($row['order_quantity']);
             $o['q'] = $qty;
             $mat_exp = $row['material_expenses'] > 0 ? $row['material_expenses'] : $row['current_mat_exp'];
             $margin = number_format($class_pm->calculateMargin($row['price'], $mat_exp), 1) . '%';
             $o['m'] = '<span class="' . ($class_pm->priceMargindIsGood($row['price'], $margin) ? 'green' : 'red') . '">' . $margin . '</span>';
             //                $el_link = '<a href="?open=elements-stock&amp;products_id='.$products_id.'&amp;hidemenu=true" class="view_webpage"></a>'; //PREVIOUS
             $el_link = '<a href="?open=products-elements-stock&amp;products_id=' . $products_id . '&amp;paid=' . $row['products_articles_id'] . '&amp;qty=' . $qty . '&amp;status=' . $row['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>';
             switch ($row['stock_status']) {
                 case '0':
                     $stock_status = '<strong class="red">!</strong>';
                     if ($status == '8') {
                         //$do_status = statusNameShort($row['depot_orders_status']);
                         $do_status = $row['depot_orders_status'] == '4' && isset($row['depot_orders_prod_status']) && $row['depot_orders_prod_status'] != '' ? statusNameProduction($row['depot_orders_prod_status'], false, true) : statusNameShort($row['depot_orders_status']);
                         if (!is_array($do_status)) {
                             //$stock_status = '<span class="red">'.$do_status.'</span>';
                             $stock_status = '<a href="?open=depot-order&amp;id=' . $row['depot_orders_id'] . '&amp;hidemenu=true" title="MMO product, current status is ' . $do_status . '" class="red view_webpage">' . $do_status . '</a>';
                         }
                     }
                     break;
                 case 'R':
                     $show_btn_inprod = true;
                     $stock_status = $el_link . '<abbr title="Element Stock OK, Ready for Production" class="green">OK</abbr>';
                     break;
                 case 'S':
                     $show_btn_insrcn = true;
                     $stock_status = $el_link . '<abbr title="Element Stock Need Sourcing" class="red">NS</abbr>';
                     break;
                 case 'P':
                     $show_btn_inprod = true;
                     $stock_status = $pr_link . '<abbr title="Use Finished Goods Stock" class="green">FG</abbr>';
                     break;
                 case 'D':
                     if (is_null($row['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=' . $row['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>';
             }
             if ($show_stock_status) {
                 $o['s'] = $stock_status;
             }
             if ($status == '3') {
                 $o['pc1'] = $row['print_count'] > 0 ? '<img title="Printed ' . $row['print_count'] . ' time(s)" src="images/icon-tick.png">' : '<img title="Not yet printed" src="images/icon-tick-dis.png">';
                 $o['pc2'] = $row['print_confirmed'] > 0 ? '<img title="Scanned ' . $row['print_confirmed'] . ' time(s)" src="images/icon-tick.png">' : '<img title="Not yet scanned" src="images/icon-tick-dis.png">';
             }
             if ($status == '4' && $sub_prod_show_line_only) {
                 $o['g'] = isset($row['prod_status']) && $row['prod_status'] != '' ? strtoupper(statusNameProduction($row['prod_status'], true)) : '';
             }
             $action = '';
             //late button
             $nolate_buttons = in_array($row['jng_sp_id'], $this->sp_nolatebtns);
             $delay_info_sent = $this->isDelayInfoSent($row['jng_sp_orders_items_id']);
             $nmi_tolerance = 2;
             //tolerance in days before showing NMI=>LATE button in Sourcing Tab
             $rsd_plain = $this->reportedShippingDate($order_date, $status, $row['delivery_time'], $row['delivery_replacement_time'], true);
             $disabled = 'disabled="disabled"';
             $delay_class = '';
             if ($nolate_buttons) {
                 $delay_class = ' red';
             } else {
                 if ($delay_info_sent) {
                     $delay_class = ' green';
                 } else {
                     if ($row['status'] != '2') {
                         $disabled = '';
                     } else {
                         if (time() > $rsd_plain + ($nmi_tolerance + 1) * 24 * 60 * 60) {
                             $disabled = '';
                         }
                     }
                 }
             }
             $late_button = '<input type="button" class="actbtn' . $delay_class . '" name="delay" value="LATE" title="Inform SP/Cust about delivery delay" ' . $disabled . ' />';
             if ($row['status'] == '1') {
                 if (!$order_vorkasse_unpaid) {
                     if ($row['stock_status'] == 'P' || $row['stock_status'] == 'R' || $row['stock_status'] == 'W') {
                         $action .= '<input type="button" class="actbtn green" name="3" value="Ready" title="Set to Ready for Production" style="width:70px;" />';
                     } elseif ($row['stock_status'] == 'S') {
                         $action .= '<input type="button" class="actbtn red" name="2" value="Sourcing" title="Set to In Sourcing" style="width:70px;" />';
                     }
                     $action .= '<input type="button" class="actbtn" name="10" value="Cancel" title="Cancel this product" />';
                 } else {
                     if ($row['jng_sp_id'] == '8') {
                         $action .= '<span class="green">Waiting Payment Status</span>';
                     } else {
                         if ($row['last_sent_date'] == '') {
                             $action .= '<span class="green">Reminder Not Sent</span>';
                             /*
                             if(!in_array($row['orders_id'],$orders_vorkasse_notice)) {
                                 $orders_vorkasse_notice[] = $row['orders_id'];
                                 $action .= '<input type="button" class="actbtn" name="reminder" value="Reminder" title="Send payment reminder to customer" />';
                             } else {
                                 $action .= '<input type="button" value="Reminder" disabled="disabled" />';
                             }
                             */
                         } else {
                             $overtime = strtotime($row['last_sent_date']) < strtotime('-' . PAYMENT_METHOD_BANK_TRANSFER_OVERDUE);
                             if ($row['sent_count'] > 1) {
                                 $action .= '<span class="red">Cancel Notification Sent</span>';
                             } else {
                                 $action .= '<span class="blue">Reminder Sent</span>';
                             }
                             /*
                             if(!in_array($row['orders_id'],$orders_vorkasse_notice) && $overtime) {
                                 $orders_vorkasse_notice[] = $row['orders_id'];
                                 $action .= '<input type="button" class="actbtn red" name="unpaidcancel" value="CANCEL" title="Cancel order and send email notification to customer" />';
                             } else {
                                 $btn_text = ($overtime) ? 'CANCEL' : 'Reminder Sent';
                                 $action .= '<input type="button" value="'.$btn_text.'" disabled="disabled" />';
                             }
                             */
                         }
                     }
                 }
             }
             //                if($row['status']<='2') $action .= '<input type="button" class="actbtn" name="3" value="Ready" title="Set to Ready for Production" />';
             if ($row['status'] == '2') {
                 $action .= '<input type="button" class="actbtn" name="3" value="Ready" title="Set to Ready for Production" />';
                 $action .= $late_button;
                 $action .= '<input type="button" class="actbtn" name="1" value="N" title="Set back to New" />';
                 $action .= '<input type="button" class="actbtn" name="10" value="C" title="Cancel this product" />';
             }
             /*
                             if($row['status']=='1') {
                $action .= '<input type="button" class="actbtn" name="2" value="Sourcing" title="Set to In Sourcing" />';
                $action .= '<input type="button" class="actbtn" name="10" value="C" title="Cancel this product" />';
                             }
             */
             if ($row['status'] == '3') {
                 //$action .= '<input type="button" class="actbtn" name="4" value="PI & Set2Prod" title="Print PI and Set to In Production" />';
                 //$action .= $late_button;
                 if (!$USE_ORDER_FILTER_TO_ALLOW_PRINTING_PI) {
                     $hid = '';
                     $action .= '<input type="button" class="actbtn" name="printpi" value="Print PI" title="Print Production Instruction" ' . $hid . '/>';
                     $action .= '<input type="hidden" name="oi_id_cols" value="' . $row['jng_sp_orders_items_id'] . '" />';
                 }
                 //$action .= '<input type="button" class="actbtn" name="1" value="N" title="Set back to New" />';
                 $action .= '<input type="button" class="actbtn" name="10" value="C" title="Cancel this product" />';
                 $action .= '<input type="button" class="actbtn" name="2" value="S" title="Set to In Sourcing" />';
             }
             if ($row['status'] == '4') {
                 $action .= '<input type="button" class="actbtn" name="5" value="Finish" title="Set to Finish" />';
                 $action .= $late_button;
                 $action .= '<input type="button" class="actbtn" name="4" value="PI" title="Reprint Production Instruction" />';
                 $action .= '<input type="button" class="actbtn" name="2" value="S" title="Set to In Sourcing" />';
                 $action .= '<input type="button" class="actbtn" name="10" value="C" title="Cancel this product" />';
                 $prod_sub_status = getProductionSubStatus(4);
                 if (count($prod_sub_status) > 0) {
                     $action .= '<br/>';
                 }
                 foreach ($prod_sub_status as $pss => $pss_name) {
                     if (in_array($pss, $PROD_SUBSTATUS_USE_LINE)) {
                         continue;
                     }
                     if ($pss == $sub_status[0]) {
                         continue;
                     }
                     $action .= '<input type="button" class="actbtn" name="4-' . $pss . '" value="' . $pss . '" title="Moved to ' . $pss_name . '" />';
                 }
             }
             if ($row['status'] == '5') {
                 //$action .= '<input type="button" class="actbtn" name="6" value="Package" title="Add to Selected Package" '.((!$packages_exist) ? 'style="display:none;"' : '').'/>';
                 $action .= '<input type="button" class="actbtn" name="4-P" value="Prod" title="Set back to Production" />';
                 $action .= $late_button;
             }
             if ($row['status'] == '8') {
                 $action .= '<input type="button" class="actbtn" name="10" value="Cancel" title="Cancel this product" />';
             }
             if ($row['status'] == '10') {
                 $action .= '<input type="button" class="actbtn" name="1" value="Revive" title="Revive this product as New" />';
             }
             if ($row['status'] == '14') {
                 $action .= '<input type="button" class="actbtn" name="16" value="Package" title="Add to Selected Package" ' . (!$packages_exist ? 'style="display:none;"' : '') . '/>';
                 $action .= '<input type="button" class="actbtn" name="15" value="Keep" title="Set to Keep" />';
             }
             if ($row['status'] == '15') {
                 $action .= '<input type="button" class="actbtn" name="14" value="Return" title="Set Back to Return" />';
             }
             if ($row['confirm_delivery'] == '1' && $row['status'] < 14) {
                 $action = '<div class="green">confirmed</div>';
             }
             //Default Row Action Value (id, status, stock status)
             $action .= '<input type="hidden" id="oiid-' . $row['jng_sp_orders_items_id'] . '" name="oi_id" value="' . $row['jng_sp_orders_items_id'] . '" >';
             $action .= '<input type="hidden" name="oi_status" value="' . $row['status'] . '" >';
             $action .= '<input type="hidden" name="csl_type" value="' . $row['list_type'] . '" />';
             if ($show_stock_status) {
                 $action .= '<input type="hidden" name="oi_stock_status" value="' . $row['stock_status'] . '" >';
             }
             $o['t'] = $action;
             if ($order_vorkasse_unpaid) {
                 $orders_vorkasse_unpaid[$row['jng_sp_orders_items_id']] = $o;
             } elseif ($order_sent_unconfirmed) {
                 $orders_sent_unconfirmed[$row['jng_sp_orders_items_id']] = $o;
             } else {
                 $orders[$row['jng_sp_orders_items_id']] = $o;
             }
         }
         $buttons = '';
         switch ($status) {
             case '1':
                 //hide by request of markus so pic must check line by line
                 //if($show_btn_inprod && $show_btn_insrcn) $buttons .= '<input type="button" class="grpbtn button" name="stockstatusall" value="Set ALL" title="Set all product status according to the stock status" />';
                 //if($show_btn_insrcn) $buttons .= '<input type="button" class="grpbtn button" name="stockstatusns" value="Set all NS to Sourcing" title="Set all product with status NS to In Sourcing" />';
             //hide by request of markus so pic must check line by line
             //if($show_btn_inprod && $show_btn_insrcn) $buttons .= '<input type="button" class="grpbtn button" name="stockstatusall" value="Set ALL" title="Set all product status according to the stock status" />';
             //if($show_btn_insrcn) $buttons .= '<input type="button" class="grpbtn button" name="stockstatusns" value="Set all NS to Sourcing" title="Set all product with status NS to In Sourcing" />';
             case '2':
                 //hide by request of markus so pic must check line by line
                 //if($show_btn_inprod) $buttons .= '<input type="button" class="grpbtn button" name="stockstatusok" value="Set all OK/FG to Ready" title="Set all product with status OK/FG to Ready for Production" />';
                 break;
             case '3':
                 //hide due to printing PI is now done per order
                 //$buttons .= 'Product Amount: <input type="text" class="iwbutton" id="pi_print_amount" name="ppa" value="10" title="Set number of products to print" style="width:50px;text-align=center;" />';
                 //$buttons .= ' <input type="button" class="grpbtn button" name="printmultpi" value="Print PI and set to Production" title="Print Production Instruction of a set number of products" />';
                 //if(!$USE_ORDER_FILTER_TO_ALLOW_PRINTING_PI) {
                 //    $buttons .= '<input type="button" class="grpbtn button" name="togglehideoi" value="Toggle Printed" title="Show or hide already printed items" />';
                 //} else {
                 $buttons .= '<div>';
                 $buttons .= '<input type="button" id="btn-reprint-pi-now" class="button help" value="REPRINT NOW for All Already Printed, Unscanned PI (0)" title="Reprint automatically NOW for all PI which<br/><strong>Already printed but not EAN scanned yet</strong>"/>&nbsp;&nbsp;&nbsp;';
                 $buttons .= '<input type="button" id="btn-reprint-pi-nextbatch" class="button help" value="REPRINT ON NEXT BATCH for All Already Printed, Unscanned PI (0)" title="Reprint ON NEXT BATCH print PI for all PI which<br/><strong>Already printed but not EAN scanned yet</strong>"/><br/><br/>';
                 $buttons .= '</div>';
                 $buttons .= '<table class="form" border="0" cellpadding="0" cellspacing="0"><tr>';
                 $buttons .= '<td class="bold">Show Products</td>';
                 $buttons .= '<td style="padding-left:30px;"><input id="rb-orf-2" type="radio" class="readyfilter" name="readyfilter" value="2"/></td>';
                 $buttons .= '<td><label for="rb-orf-2">Unprinted <span id="orfc-up">(0)</span></label></td>';
                 //$buttons .= '<td style="padding-left:30px;"><input id="rb-orf-1" type="radio" class="readyfilter" name="readyfilter" value="1" /></td>';
                 //$buttons .= '<td><label for="rb-orf-1">Ready to be printed <span id="orfc-rp">(0)</span></label></td>';
                 $buttons .= '<td style="padding-left:30px;"><input id="rb-orf-4" type="radio" class="readyfilter" name="readyfilter" value="4" /></td>';
                 $buttons .= '<td><label for="rb-orf-4">Already Printed <span id="orfc-ap">(0)</span></label></td>';
                 $buttons .= '<td style="padding-left:30px;"><input id="rb-orf-5" type="radio" class="readyfilter" name="readyfilter" value="5" /></td>';
                 $buttons .= '<td><label for="rb-orf-5">Already Printed, Unscanned <span id="orfc-apun">(0)</span></label></td>';
                 $buttons .= '<td style="padding-left:30px;"><input id="rb-orf-3" type="radio" class="readyfilter" name="readyfilter" value="3" checked="checked" /></td>';
                 $buttons .= '<td><label class="bold" for="rb-orf-3">All <span id="orfc-al">(0)</span></label></td>';
                 $buttons .= '</tr></table>';
                 //}
                 break;
             case '5':
                 $jp_mb = new messagebox();
                 $jp_mb->add('Package Management is prohibited here, please <a href="?open=packaging" class="bold">click here and use module Packaging Process</a>');
                 $buttons = $jp_mb->build();
                 break;
             case '14':
                 if ($jng_sp_id == '0') {
                     $jp_mb = new messagebox();
                     $jp_mb->add('You must select a Sales Partner before managing packages for ' . ($status == '5' ? 'finished' : 'returned') . ' products, please change the <strong>All Sales Partners</strong> filter to a specific SP.', 'green');
                     $buttons = $jp_mb->build();
                 } else {
                     if ($packages_exist) {
                         $packages = '<h3>';
                         $packages .= 'Package: ' . $class_jp->packageCombo($usable_packages, 'package', '', 'id="selpack"');
                         $packages .= ' <input type="button" class="pkgbtn" name="addall2pack" value="Add all products to this Package" title="Add all listed products to the selected package" />';
                         $packages .= '</h3>';
                     } else {
                         $packages = '<h3>Please create a new package</h3>';
                     }
                     $buttons .= '<div style="float:right;"><input type="button" class="pkgbtn button" name="createnewpackage" value="Create New Package" title="Create a new package for shipping" /></div>';
                     $buttons .= '<div id="pack_cont" style="padding:10px 0px;">' . $packages . '</div>';
                 }
                 break;
             case '16':
                 if ($jng_sp_id == '0') {
                     //$buttons .= '<input type="button" class="button grpbtn" name="printpackagechecklist" value="Print Checklist" title="Print Package Checklist" />';
                     $buttons .= '<input type="button" class="button grpbtn" name="printpackagefakeinvoice" value="Print Invoice" title="Print Fake Invoice for Bali Customs" />';
                     $buttons .= '<input type="button" class="button grpbtn" name="sendpackage" value="Send to Bali" title="Send this Package to Bali" />';
                 } else {
                     $jp_mb = new messagebox();
                     $jp_mb->add('Please change the SP filter to <strong>All Sales Partners</strong> to continue.', 'green');
                     $buttons = $jp_mb->build();
                 }
                 break;
         }
         $barcode_rule1 = $status == 3;
         $barcode_rule2 = $status == 4;
         //$barcode_rule2 = ($status==5 && $jng_sp_id!='0');
         if ($barcode_rule1 || $barcode_rule2) {
             $style = $status == 5 && !$packages_exist ? 'style="display:none;"' : '';
             //$buttons .= '<input type="button" class="button barcode-form-trigger" value="BARCODE ENTRY" '.$style.' />';
         }
         if ($buttons != '') {
             $buttons = '<div class="spb" style="margin-bottom:10px;"><input type="hidden" name="grp_status" value="' . $status . '" />' . $buttons . '</div>';
         }
         $result .= '<div id="sp-orders-' . $status . '">';
         $result .= $buttons;
         //DRAW MANUALLY
         $orders_total = count($orders);
         $orders_sent_unconfirmed_total = count($orders_sent_unconfirmed);
         $orders_vorkasse_unpaid_total = count($orders_vorkasse_unpaid);
         if ($status == '9') {
             if ($orders_sent_unconfirmed_total > 0) {
                 $result .= '<h3 class="red">Unconfirmed to Sales Partner (' . $orders_sent_unconfirmed_total . ')</h3>';
                 $result .= $this->drawTableListProduct($header, $orders_sent_unconfirmed, $orders_items);
                 $result .= '<div>&nbsp;</div>';
             }
             $result .= '<h3 class="green">Recently Confirmed to Sales Partner (' . $orders_total . ')</h3>';
         }
         if ($orders_total > 0) {
             $result .= $this->drawTableListProduct($header, $orders, $orders_items, $USE_ORDER_FILTER_TO_ALLOW_PRINTING_PI, 5, $order_pi_print_count, $order_pi_ready, $order_pi_collection, $order_pi_unscanned);
             $result .= '<div>&nbsp;</div>';
         }
         if ($orders_vorkasse_unpaid_total > 0) {
             $header['d'] = 'Date';
             unset($header['d2']);
             $result .= '<h3 class="red">Unpaid Prepayment (' . $orders_vorkasse_unpaid_total . ')<span class="notice"> - No need to process these orders</span></h3>';
             $result .= $this->drawTableListProduct($header, $orders_vorkasse_unpaid, $orders_items, $USE_ORDER_FILTER_TO_ALLOW_PRINTING_PI, 4);
         }
         if ($status == '5') {
             $result .= '<div id="crnew-pack-form" style="display:none;">';
             $result .= 'Leave blank to use auto-generated code<br />';
             $result .= '<input type="text" id="crnew-pack-form-pcode" value="" class="iwbutton" />';
             $result .= '<input type="button" id="crnew-pack-form-submit" value="Create!" class="button" />';
             $result .= '</div>';
         }
         $result .= '</div>';
     } else {
         $result .= '<h3 style="margin:0;">No Orders in this status</h3>';
     }
     return $result;
 }