Example #1
0
 $order_product['qty'] = $row['products_quantity'];
 $order_product['price2'] = displayCurrency($order_currency, $p_qty_pri);
 if ($row['status'] == '-') {
     $status = $statusName[$row['status']];
 } else {
     $status = '<a href="?open=order-history&amp;opid=' . $op_id_temp . '&amp;hidemenu=true" class="view_webpage">';
     if (statusIsCancelled($row['status'])) {
         $order_product['qty'] = '<span class="notice">' . $row['products_quantity'] . '</span>';
         $order_product['price2'] = '<span class="notice">-</span>';
         $status .= statusName($row['status']);
     } else {
         $status .= $statusName[$row['status']];
     }
     $status .= '</a>';
 }
 $stock_status = stockStatusDisplay($row['stock_status'], $row['status'], $row['products_id'], $row['products_articles_id'], $row['products_quantity'], $do);
 $stock_status .= " / " . modeName($row['mode']);
 $order_product['source'] = $stock_status;
 $order_product['nick'] = $status;
 //if($row['products_problem']=='1') $order_product['name'] = '<img src="images/icon-yellow.png" onclick="alert(\'This Product is marked as damage/missing on arrival\');" align="left" title="This Product is marked as damage/missing on arrival" /> ' . $order_product['name'];
 $action = '<input type="hidden" name="opid" value="' . $row['orders_products_id'] . '" id="opid-' . $row['orders_products_id'] . '" />';
 $action .= '<input type="hidden" name="status" value="' . $row['status'] . '" />';
 $action .= '<input type="hidden" name="print_count" value="' . $row['print_count'] . '" />';
 if ($row['status'] < 9) {
     $action .= '<input type="button" name="Cancel" value="Cancel" />';
     $cancelable = true;
 }
 $order_product['login'] = $action;
 $order_products[] = $order_product;
 if ($row['status'] != '10' && $row['status'] != '12') {
     $op_total_product += $row['products_quantity'];
 function drawOrderDisplay($order_type, $order_id, $displaypart = 'ALL', $excludecurrentorderinhistory = true)
 {
     //$displaypart = 'ALL' / 'NEW' / 'HISTORY'
     global $class_do, $class_pm, $class_pa, $class_mc, $class_jo, $class_jc, $class_o, $sp_list;
     //ORDERED PRODUCTS DISPLAY SETTING
     $col_limit = 5;
     //max no of columns
     $row_limit = 5;
     //max no of rows
     $border = '1';
     //border width
     $imgsize = '80';
     //image size
     $padding = '5';
     //box padding
     $margin = '10';
     //box margin
     $po_limit = $col_limit * $row_limit;
     //max no of products - auto calc
     $powidth = ceil($col_limit * ($imgsize + 2 * ($border + $padding) + $margin) / 10) * 10;
     $total_price = 0;
     if ($order_type == 'SP') {
         use_class('jng_sp_customers_special');
         $csl = new jng_sp_customers_special();
         $order = $class_jo->retrieveDetail($order_id);
         $order_source = $sp_list[$order['jng_sp_id']]['name'];
         $order_products = $class_jo->retrieveItems($order_id);
         $customer = $class_jc->retrieveDetail(null, $order['jng_sp_id'], $order['customer_billing_id']);
         $list_type = $csl->getListType($customer['jng_sp_customers_id']);
         $cust_crown = $csl->getTypeSymbol($list_type, $customer['jng_sp_customers_id']);
         $customer_name = $cust_crown . $order['customer_billing_firstname'] . ' ' . $order['customer_billing_lastname'];
         $customer_address = $order['customer_billing_address'];
         if ($order['customer_billing_address2'] != '') {
             $customer_address .= ', ' . $order['customer_billing_address2'];
         }
         $customer_address .= ', ' . $order['customer_billing_postcode'];
         $customer_address .= ' ' . $order['customer_billing_city'];
         $customer_address .= ', ' . $order['customer_billing_country'];
         $products_ordered = $class_jc->retrieveOrdersItems($customer['jng_sp_customers_id']);
         $colname_order_id = 'jng_sp_orders_id';
         $colname_items_id = 'jng_sp_orders_items_id';
         $colname_order_date = 'order_date';
         $colname_order_qty = 'order_quantity';
         $colname_return_qty = 'return_quantity';
         $colname_products_id = 'products_id';
         $colname_products_code = 'article_number';
         $colname_articles_id = 'products_articles_id';
         $colname_custom_text1 = null;
         $colname_custom_text2 = null;
         $colname_custom_image = null;
         $order_history_display = null;
         $total_price = getTotalOrderAmount('S', $order_id);
     } elseif ($order_type == 'JG') {
         use_class('customers_special_list');
         $csl = new customers_special_list();
         $order = $class_o->retrieveDetail($order_id);
         $order_source = 'JULIE&amp;GRACE';
         $total_price = getTotalOrderAmount('J', $order_id, $order['currency']);
         $order_products = $class_o->retrieveProducts($order_id);
         //$customer = $class_mc->retrieveDetail($order['customers_id']);
         $list_type = $csl->getListType($order['customers_id']);
         $cust_crown = $csl->getTypeSymbol($list_type, $order['customers_id']);
         $customer_name = $cust_crown . $order['customers_name'];
         $customer_address = '';
         if ($order['customers_company'] != '') {
             $customer_address .= $order['customers_company'] . ', ';
         }
         $customer_address .= $order['customers_street_address'];
         $customer_address .= ', ' . $order['customers_postcode'];
         $customer_address .= ' ' . $order['customers_city'];
         $customer_address .= ', ' . $order['customers_country'];
         $products_ordered = $class_mc->retrieveOrdersProducts($order['customers_id'], 'op.status>0');
         $colname_order_id = 'orders_id';
         $colname_items_id = 'orders_products_id';
         $colname_order_date = 'date_purchased';
         $colname_order_qty = 'products_quantity';
         $colname_return_qty = 'return_quantity';
         $colname_products_id = 'products_id';
         $colname_products_code = 'products_model';
         $colname_articles_id = 'products_articles_id';
         $colname_custom_text1 = 'customers_text_line1';
         $colname_custom_text2 = 'customers_text_line2';
         $colname_custom_image = 'customers_image';
         $order_history_display = null;
     } elseif ($order_type == 'DP') {
         $order = $class_do->retrieveDetail($order_id);
         $product_detail = $class_pm->retrieveDetail($order['products_id'], 'p');
         $order['products_image'] = $product_detail['p']['products_image'];
         $order['products_model'] = $product_detail['p']['products_model'];
         $order['order_item_count'] = '1';
         $order['order_item_total'] = '1';
         $order_products = array();
         $order_products[] = $order;
         $colname_order_id = 'depot_orders_id';
         $colname_items_id = 'depot_orders_id';
         $colname_order_date = 'order_date';
         $colname_order_qty = 'quantity';
         $colname_return_qty = '';
         $colname_products_id = 'products_id';
         $colname_products_code = 'products_model';
         $colname_articles_id = 'articles_id';
         $colname_custom_text1 = null;
         $colname_custom_text2 = null;
         $colname_custom_image = null;
         if ($order['trans_type'] == 'SP' || $order['trans_type'] == 'JG') {
             if ($order['trans_type'] == 'SP') {
                 $item = $class_jo->retrieveItemDetail($order['trans_id']);
                 //if ($item['jng_sp_id'] != '2') {
                 //echo "<pre>";
                 //var_dump($item);
                 //die("ttt");
                 if ($item['stock_status'] == '0') {
                     $order_history_display = drawOrderDisplay($order['trans_type'], $item['jng_sp_orders_id'], 'HISTORY', false);
                 }
                 $total_price = getTotalOrderAmount('S', $item['jng_sp_orders_id']);
                 //}
             } else {
                 //die("test");
                 $item = $class_o->retrieveProductDetail($order['trans_id']);
                 $total_price = getTotalOrderAmount('J', $item['orders_id']);
                 if ($item['stock_status'] == '0') {
                     $order_history_display = drawOrderDisplay($order['trans_type'], $item['orders_id'], 'HISTORY', false);
                 }
             }
         }
     }
     $result = '';
     if ($displaypart == 'ALL' || $displaypart == 'NEW') {
         //NEW ORDER
         $result .= '<h2 style="position:fixed;top:0;left:0;line-height:20px;width:480px;padding:5px 10px;background:#ccc;border-right:1px inset #666;">New ' . $order_type . ' Order ' . $order_id . ' (' . $total_price . ')</h2>';
         //$result .= '<div style="position:fixed;top:30;bottom:0;left:0;width:480px;padding:10px;background:#efefef;border-right:1px inset #666;overflow:auto;">';
         $result .= '<div id="box-order-items" style="position:fixed;top:30;bottom:0;height:93%;left:0;width:480px;padding:10px;background:#efefef;border-right:1px inset #666;overflow:auto;">';
         $neworder = array();
         $no = array();
         $no['l'] = 'No';
         $no['d'] = 'Image';
         $no['t2'] = 'Info';
         $no['q'] = 'Order<br/>Qty.';
         $no['r'] = 'Stock Status<br /> and Actions';
         $neworder[] = $no;
         foreach ($order_products as $op) {
             if ($op[$colname_articles_id] > 0) {
                 $article = $class_pa->retrieveDetail($op[$colname_articles_id]);
                 $prolength = $article['length'];
             } else {
                 $product_detail = $class_pm->retrieveDetail($op[$colname_products_id], 'pnc');
                 $prolength = $product_detail['pnc']['products_length'];
             }
             $customize_info = '';
             if (!is_null($colname_custom_text1) && !is_null($colname_custom_text2)) {
                 if ($op[$colname_custom_text1] != '' || $op[$colname_custom_text2] != '') {
                     $customize_info .= '<div style="margin-top:10px;">';
                     if ($op[$colname_custom_text1] != '') {
                         $customize_info .= $op[$colname_custom_text1];
                     }
                     if ($op[$colname_custom_text2] != '') {
                         $customize_info .= '<br />' . $op[$colname_custom_text2];
                     }
                     $customize_info .= '</div>';
                 }
             }
             if (!is_null($colname_custom_image) && $op[$colname_custom_image] != '') {
                 $customize_info .= webImage($op[$colname_custom_image], '80', '80', 'Custom Image');
             }
             $length_text = $prolength > 0 ? 'Length: ' . textLength($prolength) : '<span class="notice">No Length</span>';
             //$tooltip_data = getTooltipThumbData($op[$colname_products_id], $op[$colname_articles_id], 0);
             $pdata = $class_pm->retrieveDetail($op[$colname_products_id], 'pl,sp');
             $tooltip_text = '<table class="tiny" border="0" cellpadding="0" cellspacing="0" align="center">';
             $tooltip_text .= '<tr><td width="80" title="Sold Last 30 Days">Sold L30D</td><td>' . intval($pdata['pl']['sold_monthly_1']) . ' products</td></tr>';
             $tooltip_text .= '<tr><td>Total sold</td><td>' . intval($pdata['sp']['0']['total_sold']) . ' products</td></tr>';
             $tooltip_text .= '<tr><td>Return Rate</td><td>' . number_format($pdata['sp']['0']['returned_rate'], 1) . '%</td></tr>';
             $tooltip_text .= '<tr><td>Product Age</td><td>' . $pdata['sp']['0']['active_age'] . ' days</td></tr>';
             $tooltip_text .= '</table>';
             $info = array();
             //var_dump($order_type);
             $info[] = $order_type . '-' . $op[$colname_items_id];
             $info[] = $op['products_ean'];
             $info[] = $op[$colname_products_id] . ' / ' . $op[$colname_products_code];
             $info[] = $length_text;
             $info[] = '&nbsp;';
             $info[] = '<strong>All SP Summary</strong>';
             $info[] = $tooltip_text;
             $action_hidden = '<input type="hidden" id="' . $order_type . '-' . $op[$colname_items_id] . '" name="oiid" value="' . $op[$colname_items_id] . '" />';
             $action_hidden .= '<input type="hidden" name="type" value="' . $order_type . '" />';
             $action = array();
             $action[] = stockStatusDisplay($op['stock_status'], $op['status'], $op[$colname_products_id], $op[$colname_articles_id], $op[$colname_order_qty], null);
             $action[] = '&nbsp;';
             if ($op['stock_status'] == 'S') {
                 $action[] = '<input type="button" name="2" value="&raquo; Sourcing" class="bl green" />';
             } elseif ($op['stock_status'] == 'R' || $op['stock_status'] == 'P' || $op['stock_status'] == 'W') {
                 $action[] = '<input type="button" name="3" value="&raquo; Ready" class="bl green" />';
                 //$action[] = '<input type="button" name="test" value="&raquo; Sourcing" class="bl red" />';
             }
             $action[] = '<input type="button" name="10" value="&times; Cancel" class="bl red" />';
             $no = array();
             $no['l'] = $op['order_item_count'] . '/' . $op['order_item_total'];
             $no['d'] = webImage($op['products_image'], '80', '80', 'Product Image') . $customize_info;
             $no['t2'] = implode('<br />', $info);
             if (isset($op['order_quantity'])) {
                 $order_quantity = $op['order_quantity'];
             } elseif (isset($op['products_quantity'])) {
                 $order_quantity = $op['products_quantity'];
             } else {
                 $order_quantity = $op['quantity'];
             }
             $no['q'] = $order_quantity;
             $no['r'] = $action_hidden . implode('<br />', $action);
             $neworder[] = $no;
         }
         $result .= tep_draw_table('spo', $neworder);
         $result .= '<div class="buttons"><input type="button" name="nextorder" value="Next Order" class="button" /></div>';
         $result .= '</div>';
         //NEW ORDER - CLOSER
     }
     if (!is_null($order_history_display)) {
         $result .= $order_history_display;
     } elseif ($displaypart == 'ALL' || $displaypart == 'HISTORY') {
         $result .= '<div style="margin-left:510px;color:#666;" >';
         //HISTORICAL INFO
         if ($order_type == 'DP') {
             $result .= '<h2>DEPOT ' . ($order['trans_type'] == 'AR' ? 'REFILL' : 'MANUAL ORDER') . '</h2>';
         } else {
             //var_dump($order_type);
             $result .= '<h2>Customer Detail</h2>';
             //                    $result .= '<table border="0" cellpadding="0" cellspacing="0">';
             //                    $result .= '<tr><td width="150">Customer From</td><td>'.$order_source.'</td></tr>';
             //                    $result .= '<tr><td>Customer Name</td><td>'.$customer_name.'</td></tr>';
             //                    $result .= '<tr><td>Customer Address</td><td>'.$customer_address.'</td></tr>';
             //                    $result .= '<tr><td></td><td></td></tr>';
             //                    $result .= '</table>';
             $result .= '<div class="bold">' . $order_source . '</div>';
             $result .= '<div>' . $customer_name . '</div>';
             $result .= '<div>' . $customer_address . '</div>';
             $result .= '<div>&nbsp;</div>';
             $orders_collection = array();
             $products_ordered_total = 0;
             $products_returned_total = 0;
             $products_canceled_total = 0;
             $products_inprocess_total = 0;
             foreach ($products_ordered as $pok => $pov) {
                 if ($excludecurrentorderinhistory && $pov[$colname_order_id] == $order[$colname_order_id]) {
                     unset($products_ordered[$pok]);
                 } else {
                     if (!in_array($pov[$colname_order_id], $orders_collection)) {
                         $orders_collection[] = $pov[$colname_order_id];
                     }
                     $products_ordered_total += $pov[$colname_order_qty];
                     $products_returned_total += $pov[$colname_return_qty];
                     if (statusIsCancelled($pov['status'])) {
                         $products_canceled_total += $pov[$colname_order_qty];
                     }
                     if ($pov['status'] < 9) {
                         $products_inprocess_total += $pov[$colname_order_qty];
                     }
                 }
             }
             $result .= '<h2>Customer Historical Info</h2>';
             if ($products_ordered_total > 0) {
                 $products_success_total = $products_ordered_total - ($products_inprocess_total + $products_canceled_total);
                 $return_rate = $products_returned_total == 0 ? 0 : $products_returned_total / $products_success_total * 100;
                 $process_class = $products_inprocess_total > 0 ? 'red' : 'green';
                 $success_class = $products_success_total > 0 ? 'green' : 'red';
                 $return_class = $products_returned_total > 0 ? 'red' : 'green';
                 $return_rate_class = $return_rate <= 10 ? 'green' : 'red';
                 $prevtext = $excludecurrentorderinhistory ? 'Previous' : '';
                 $result .= '<h3>&raquo; Customer ' . $prevtext . ' Orders Total = ' . count($orders_collection) . '</h3>';
                 $result .= '<h3>&raquo; Ordered Products Total = ' . $products_ordered_total . '</h3>';
                 $result .= '<h3>&raquo; Ordered Products Canceled = ' . $products_canceled_total . '</h3>';
                 $result .= '<h3 class="' . $process_class . '">&raquo; Ordered Products in Progress = ' . $products_inprocess_total . '</h3>';
                 $result .= '<h3 class="' . $success_class . '">&raquo; Ordered Products Received = ' . $products_success_total . '</h3>';
                 $result .= '<h3 class="' . $return_class . '">&raquo; Ordered Products Returns = ' . $products_returned_total . '</h3>';
                 $result .= '<h3 class="' . $return_rate_class . '">&raquo; Customer Return Rate = ' . number_format($return_rate, 1) . '%</h3>';
                 $result .= '<h3>&raquo; Recent Ordered Products List (Showing Max ' . $po_limit . ' Products): ' . '</h3>';
                 $result .= '<div style="width:' . $powidth . 'px;">';
                 $pocount = 0;
                 foreach ($products_ordered as $po) {
                     $pocount++;
                     if ($pocount <= $po_limit) {
                         if ($po[$colname_articles_id] > 0) {
                             $article = $class_pa->retrieveDetail($po[$colname_articles_id]);
                             $prolength = $article['length'];
                         } else {
                             $product_detail = $class_pm->retrieveDetail($po[$colname_products_id], 'pnc');
                             $prolength = $product_detail['pnc']['products_length'];
                         }
                         $length_text = $prolength > 0 ? textLength($prolength) : '<span class="notice">No Length</span>';
                         $status = $po['status'] == '8' ? modeName($po['mode']) : statusNameShort($po['status'], true);
                         $status_class = $po['status'] < 9 ? 'red' : 'notice';
                         $qty_class = statusIsCancelled($po['status']) > 0 ? 'notice' : 'green';
                         $result .= '<div style="float:left;border:' . $border . 'px solid #ccc;text-align:center;margin:0 ' . $margin . 'px ' . $margin . 'px 0;padding:' . $padding . 'px;">';
                         $result .= webImage($po['products_image'], $imgsize, $imgsize);
                         $result .= '<br />';
                         $result .= $length_text;
                         $result .= '<br />';
                         $result .= '<span title="Order Date">' . date('d.m.Y', strtotime($po[$colname_order_date])) . '</span>';
                         $result .= '<br />';
                         $result .= '<span class="' . $status_class . '" title="Current Status">' . $status . '</span>';
                         $result .= '<br />';
                         $result .= '<strong class="' . $qty_class . '" title="Order Quantity">+' . intval($po[$colname_order_qty]) . '</strong>';
                         $result .= ' &nbsp; ';
                         $returns = intval($po[$colname_return_qty]);
                         $retclas = $returns > 0 ? 'red' : 'notice';
                         $result .= '<strong class="' . $retclas . '" title="Return Quantity">-' . $returns . '</strong>';
                         $result .= '</div>';
                     }
                 }
                 $result .= '</div>';
                 $result .= '<div style="clear:both;">&nbsp;</div>';
             } else {
                 $result .= '<h3>&raquo; No Order Historical info, a New Customer</h3>';
             }
         }
         $result .= '</div>';
         //HISTORICAL INFO - CLOSER
     }
     return $result;
 }