httpGetVars('start_date', date('Y-m-d', time() - $pastMonths * 2592000)); $end_date = $slsc->httpGetVars('end_date', date('Y-m-d')); ?> > <?php echo TITLE; ?>
(< ' . STOCK_REORDER_LEVEL . ')'); ?>
httpGetVars('sorted', 'ASC', array('ASC', 'DESC')); $orderby = $slsc->httpGetVars('orderby', 'stock'); //db_orderby based on orderby switch($orderby) { case 'stock': default: $orderby = 'stock'; $db_orderby = 'p.products_quantity'; break; case 'model': $db_orderby = 'p.products_model'; break; case 'name': $db_orderby = 'pd.products_name'; break; } ?> 1) ? ( (int)$HTTP_GET_VARS['page'] - 1) * 30 : 0; /* SQL: setup query */ // select query incl. orderby $products_query_raw = sprintf("select p.products_id, p.products_quantity, pd.products_name, p.products_model from %s p, %s pd where p.products_id = pd.products_id and pd.language_id = '%s' and p.products_quantity <= %d group by pd.products_id order by %s %s", TABLE_PRODUCTS, TABLE_PRODUCTS_DESCRIPTION, $languages_id, STOCK_REORDER_LEVEL, $db_orderby, $sorted); //limit results $products_split = new splitPageResults($HTTP_GET_VARS['page'], 30, $products_query_raw, $products_query_numrows); //execute database query $products_query = tep_db_query($products_query_raw); while ($products = tep_db_fetch_array($products_query)) { $rows++; $products_id = $products['products_id']; /* get category path of item */ // find the products category $last_category_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = $products_id"); $last_category = tep_db_fetch_array($last_category_query); $p_category = $last_category["categories_id"]; // store and find the parent until reaching root $p_category_array = array(); do { $p_category_array[] = $p_category; $last_category_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = $p_category"); $last_category = tep_db_fetch_array($last_category_query); $p_category = $last_category["parent_id"]; } while ($p_category); $cPath_array = array_reverse($p_category_array); unset($p_category_array); /* done */ // Sold in Last x Months Query $productSold_query = tep_db_query("select sum(op.products_quantity) as quantitysum FROM " . TABLE_ORDERS . " as o, " . TABLE_ORDERS_PRODUCTS . " AS op WHERE o.date_purchased BETWEEN '" . $start_date . "' AND '" . $end_date . " 23:59:59' AND o.orders_id = op.orders_id AND op.products_id = $products_id GROUP BY op.products_id ORDER BY quantitysum DESC, op.products_id"); $productSold = tep_db_fetch_array($productSold_query); // Calculating days stock if ($products['products_quantity'] > 0) { $StockOnHand = $products['products_quantity']; $SalesPerDay = $productSold['quantitysum'] / ($pastMonths * 30); round ($SalesPerDay, 2); $daysSupply = 0; $display = y; if ($SalesPerDay > 0) { $daysSupply = $StockOnHand / $SalesPerDay; } round($daysSupply); if ($daysSupply <= '20') { $daysSupply = '' . round($daysSupply) . ' ' . DAYS . ''; } else { $daysSupply = round($daysSupply) . ' ' . DAYS; } if (($SalesPerDay == 0) && ($StockOnHand > 1)) { $display = n; $daysSupply = '+60 '. DAYS; } if ($daysSupply > ($pastMonths * 30)) { $display = n; } } else { $daysSupply = 'NA'; $display = y; } //edit: skip, because I had no time to check the code above $display = 'y'; if ($display == y) { // diverse urls used in output $url_newproduct = tep_href_link(FILENAME_CATEGORIES, tep_get_path() . '&pID=' . $products['products_id'] . '&action=new_product', 'NONSSL'); $url_product = tep_href_link(FILENAME_CATEGORIES, tep_get_path() . '&pID=' . $products['products_id']); // some tweaking to make the output just looking better $prodsold = ($productSold['quantitysum'] > 0) ? (int)$productSold['quantitysum'] : 0; $prodmodel = trim((string)$products['products_model']); $prodmodel = (strlen($prodmodel)) ? htmlspecialchars($prodmodel) : ' '; // make negative qtys red b/c people have backordered them $productsQty = (int) $products['products_quantity']; $productsQty = ($productsQty < 0) ? sprintf('%d', $productsQty) : (string) $productsQty; ?>
htmlCaptionSortLink('name', FILENAME_STATS_LOW_STOCK, TABLE_HEADING_PRODUCTS) ); ?> htmlCaptionSortLink('stock', FILENAME_STATS_LOW_STOCK, TABLE_HEADING_QTY_LEFT) ); ?>  htmlCaptionSortLink('model', FILENAME_STATS_LOW_STOCK, TABLE_HEADING_PROD_ID) ); ?>    
. ' . $products['products_name'] . ''; ?> ' . $prodmodel . ''; ?>
display_count($products_query_numrows, 30, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?> display_links($products_query_numrows, 30, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page'], "orderby=" . $orderby . "&sorted=" . $sorted); ?>