Low Stock Report v2.0
#1
Posted 10 August 2005, 01:19
WHATS NEW IN 2.0?
-------------------------
NEW FEATURES:
* It now shows you your sales on this item in the last 30 days so you can
really know if this item is really selling or not
* Estimated days stock, this is based off of the last 30 days of your sales,
if you have 0 in stock it will display NA in red, if you have 15 days or
less it will display the days in red, if you have no sales but stock it
will display +30 Days. Pretty niffty ehh? Much more accurate.
NOTE: It will only display items that need restocked that are at or below your restock level set
in admin -> Stock, regardless of how many estimated days stock you have. This is because it has
to execute a DB query for every item it estimates days of stock for so this is a way of limiting
the queries to the most relevant items (item below restock levels). Maybe someone can further
optimize my queries if they know how...
This should be a hugely helpful addition to your store, thanks to all the other authors who
wrote the previous versions and the people who wrote the stats products purchased contrib,
these two contrib are which this code is based on.
Regards,
-Keith W.
Also Purchased (AP) Preselection (cuts this resource hogging query down to nothing) -- Contribution 3294
FedEx Automated Labels -- Contribution 2244
RMA Returns system -- Contribution 1136
Sort Products By Dropdown -- Contribution 4312
Ultimate SEO URLs -- Contribution 2823
Credit Class & Gift Voucher -- Contribution 282
Cross-Sell -- Contribution 5347
#2
Posted 10 August 2005, 02:10
1054 - Unknown column 'p.last_one' in 'field list' select p.products_id, p.last_one, p.products_quantity, pd.products_name, p.products_model from products p, products_description pd where p.products_id = pd.products_id and pd.language_id = '1' and p.products_quantity <= 5 group by pd.products_id order by pd.products_name ASC limit -20, 20 [TEP STOP]
Any ideas?
#3
Posted 10 August 2005, 03:50
willross, on Aug 9 2005, 09:10 PM, said:
1054 - Unknown column 'p.last_one' in 'field list' select p.products_id, p.last_one, p.products_quantity, pd.products_name, p.products_model from products p, products_description pd where p.products_id = pd.products_id and pd.language_id = '1' and p.products_quantity <= 5 group by pd.products_id order by pd.products_name ASC limit -20, 20 [TEP STOP]
Any ideas?
I had the same error after installing an update. I just added a last_one to TABLE Products. Now I get another error:
Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121
Can anybody suggest a correct way to fix an errors?
Thanks,
Irina.
#4
Posted 10 August 2005, 04:10
willross, on Aug 10 2005, 10:10 AM, said:
1054 - Unknown column 'p.last_one' in 'field list' select p.products_id, p.last_one, p.products_quantity, pd.products_name, p.products_model from products p, products_description pd where p.products_id = pd.products_id and pd.language_id = '1' and p.products_quantity <= 5 group by pd.products_id order by pd.products_name ASC limit -20, 20 [TEP STOP]
Any ideas?
delete that field from the query, it is not used anywhere as far as I can tell
#5
Posted 10 August 2005, 14:34
boxtel, on Aug 10 2005, 04:10 AM, said:
It's not used, that is a field on my site which I accidently left in the query.
Proper query should be:
$products_query_raw = "select p.products_id, p.products_quantity, pd.products_name, p.products_model from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . $languages_id. "' and p.products_quantity <= " . STOCK_REORDER_LEVEL . " group by pd.products_id order by $db_orderby $sorted";
I've posted the update to the contribution page.
So what do you all think of the new features?
Also Purchased (AP) Preselection (cuts this resource hogging query down to nothing) -- Contribution 3294
FedEx Automated Labels -- Contribution 2244
RMA Returns system -- Contribution 1136
Sort Products By Dropdown -- Contribution 4312
Ultimate SEO URLs -- Contribution 2823
Credit Class & Gift Voucher -- Contribution 282
Cross-Sell -- Contribution 5347
#6
Posted 10 August 2005, 14:37
Quote
Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121 Warning: Division by zero in .............\osCommerce\admin\stats_low_stock.php on line 121
Can anybody suggest a correct way to fix an errors?
Thanks,
Irina.
When you delete p.last_one from the query do you still get this error?
Edited by homewetbar, 10 August 2005, 14:38.
Also Purchased (AP) Preselection (cuts this resource hogging query down to nothing) -- Contribution 3294
FedEx Automated Labels -- Contribution 2244
RMA Returns system -- Contribution 1136
Sort Products By Dropdown -- Contribution 4312
Ultimate SEO URLs -- Contribution 2823
Credit Class & Gift Voucher -- Contribution 282
Cross-Sell -- Contribution 5347
#7
Posted 10 August 2005, 14:50
homewetbar, on Aug 10 2005, 09:37 AM, said:
Warning: Division by zero in ......\osCommerce\admin\stats_low_stock.php on line 143 Warning: Division by zero in ......\osCommerce\admin\stats_low_stock.php on line 143 Warning: Division by zero in ......\osCommerce\admin\stats_low_stock.php on line 143 Warning: Division by zero in ......\osCommerce\admin\stats_low_stock.php on line 143 Warning: Division by zero in ......\osCommerce\admin\stats_low_stock.php on line 143 Warning: Division by zero in ......\osCommerce\admin\stats_low_stock.php on line 143 Warning: Division by zero in ......\osCommerce\admin\stats_low_stock.php on line 143 Warning: Division by zero in ......\osCommerce\admin\stats_low_stock.php on line 143Even if I upload your new v2.0a, I still get this error.
Regards,
irina.
#8
Posted 10 August 2005, 16:22
I had the same problem and updated the stats_low_stock.php file with the following from line 137 until 145
<-- ORIGINAL -->
// Calculating days stock
if ($products['products_quantity'] > 0) {
$StockOnHand = $products['products_quantity'];
$SalesPerDay = $productSold['quantitysum'] / 30;
round ($SalesPerDay, 2);
$daysSupply = 0;
$daysSupply = $StockOnHand / $SalesPerDay;
<-- CHANGED -->
// Calculating days stock
if ($products['products_quantity'] > 0) {
$StockOnHand = $products['products_quantity'];
$SalesPerDay = $productSold['quantitysum'] / 30;
round ($SalesPerDay, 2);
$daysSupply = 0;
if ($SalesPerDay > 0) {
$daysSupply = $StockOnHand / $SalesPerDay;
}
#9
Posted 10 August 2005, 17:18
Huey_AU, on Aug 10 2005, 11:22 AM, said:
I had the same problem and updated the stats_low_stock.php file with the following from line 137 until 145
<-- ORIGINAL -->
// Calculating days stock
if ($products['products_quantity'] > 0) {
$StockOnHand = $products['products_quantity'];
$SalesPerDay = $productSold['quantitysum'] / 30;
round ($SalesPerDay, 2);
$daysSupply = 0;
$daysSupply = $StockOnHand / $SalesPerDay;
<-- CHANGED -->
// Calculating days stock
if ($products['products_quantity'] > 0) {
$StockOnHand = $products['products_quantity'];
$SalesPerDay = $productSold['quantitysum'] / 30;
round ($SalesPerDay, 2);
$daysSupply = 0;
if ($SalesPerDay > 0) {
$daysSupply = $StockOnHand / $SalesPerDay;
}
Parse error: parse error in ........\osCommerce\admin\stats_low_stock.php on line 200So, your fix doesn't work for me.
Regards,
Irina.
#10
Posted 10 August 2005, 17:38
I've copy pasted from // Sold in Last x Months Query (approx 133) to ?> after $dayssupply=blahblah on line 159..
it might be a missing } or something.. I also just moved the round($daysSupply); into the if ($SalesPerDay > 0) statement too.
// 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'] / 30;
round ($SalesPerDay, 2);
$daysSupply = 0;
if ($SalesPerDay > 0) {
$daysSupply = $StockOnHand / $SalesPerDay;
round($daysSupply);
}
if ($daysSupply <= '15') {
$daysSupply = '<font color=red>' . round($daysSupply) . ' ' . DAYS . '</font>';
} else {
$daysSupply .= ' ' . DAYS;
}
if ($SalesPerDay == 0) {
$daysSupply = '+30 '. DAYS;
}
} else {
$daysSupply = '<font color=red>NA</font>';
}
?>
Edited by Huey_AU, 10 August 2005, 17:40.
#11
Posted 10 August 2005, 17:58
Huey_AU, on Aug 10 2005, 12:38 PM, said:
I've copy pasted from // Sold in Last x Months Query (approx 133) to ?> after $dayssupply=blahblah on line 159..
it might be a missing } or something.. I also just moved the round($daysSupply); into the if ($SalesPerDay > 0) statement too.
// 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'] / 30;
round ($SalesPerDay, 2);
$daysSupply = 0;
if ($SalesPerDay > 0) {
$daysSupply = $StockOnHand / $SalesPerDay;
round($daysSupply);
}
if ($daysSupply <= '15') {
$daysSupply = '<font color=red>' . round($daysSupply) . ' ' . DAYS . '</font>';
} else {
$daysSupply .= ' ' . DAYS;
}
if ($SalesPerDay == 0) {
$daysSupply = '+30 '. DAYS;
}
} else {
$daysSupply = '<font color=red>NA</font>';
}
?>
Great contrib, added some useful fields.
Thanks again,
Irina.
#12
Posted 10 August 2005, 18:23
Irin, on Aug 10 2005, 05:18 PM, said:
Parse error: parse error in ........\osCommerce\admin\stats_low_stock.php on line 200So, your fix doesn't work for me.
Regards,
Irina.
I'm surprised his fix did not work maybe your error is being caused by is $productSold['quantitysum'] = 0 then it would be 0/30. Try this I think it should fix it if that is the problem.
CHANGE:
// Calculating days stock
if ($products['products_quantity'] > 0) {
$StockOnHand = $products['products_quantity'];
$SalesPerDay = $productSold['quantitysum'] / 30;
round ($SalesPerDay, 2);
$daysSupply = 0;
$daysSupply = $StockOnHand / $SalesPerDay;
TO:
// Calculating days stock
if ($products['products_quantity'] > 0) {
$StockOnHand = $products['products_quantity'];
if ($productSold['quantitysum'] > 0) {
$SalesPerDay = $productSold['quantitysum'] / 30;
round ($SalesPerDay, 2);
$daysSupply = 0;
$daysSupply = $StockOnHand / $SalesPerDay;
} else {
$daysSupply = '+30 '. DAYS;
}
Edited by homewetbar, 10 August 2005, 18:26.
Also Purchased (AP) Preselection (cuts this resource hogging query down to nothing) -- Contribution 3294
FedEx Automated Labels -- Contribution 2244
RMA Returns system -- Contribution 1136
Sort Products By Dropdown -- Contribution 4312
Ultimate SEO URLs -- Contribution 2823
Credit Class & Gift Voucher -- Contribution 282
Cross-Sell -- Contribution 5347
#13
Posted 10 August 2005, 18:28
homewetbar, on Aug 10 2005, 01:23 PM, said:
CHANGE:
// Calculating days stock
if ($products['products_quantity'] > 0) {
$StockOnHand = $products['products_quantity'];
$SalesPerDay = $productSold['quantitysum'] / 30;
round ($SalesPerDay, 2);
$daysSupply = 0;
$daysSupply = $StockOnHand / $SalesPerDay;
TO:
// Calculating days stock
SalesPerDay = '';
if ($products['products_quantity'] > 0) {
$StockOnHand = $products['products_quantity'];
if ($productSold['quantitysum'] > 0) {
$SalesPerDay = $productSold['quantitysum'] / 30;
round ($SalesPerDay, 2);
$daysSupply = 0;
$daysSupply = $StockOnHand / $SalesPerDay;
} else {
$daysSupply = '+30 '. DAYS;
}
Regards,
Irina.
#14
Posted 10 August 2005, 18:34
Edited by Huey_AU, 10 August 2005, 18:36.
#15
Posted 11 August 2005, 20:25
Will this contribution show the stock level of different color attributes of a product or just the stock of the product?
#16
Posted 11 August 2005, 20:26
modom, on Aug 11 2005, 08:25 PM, said:
Will this contribution show the stock level of different color attributes of a product or just the stock of the product?
Just stock of the product
Also Purchased (AP) Preselection (cuts this resource hogging query down to nothing) -- Contribution 3294
FedEx Automated Labels -- Contribution 2244
RMA Returns system -- Contribution 1136
Sort Products By Dropdown -- Contribution 4312
Ultimate SEO URLs -- Contribution 2823
Credit Class & Gift Voucher -- Contribution 282
Cross-Sell -- Contribution 5347
#17
Posted 15 August 2005, 02:38
1064 - You have an error in your SQL syntax near '' at line 1
select parent_id from categories where categories_id =
[TEP STOP]
How do you fix this?
#18
Posted 15 August 2005, 12:29
modom, on Aug 15 2005, 02:38 AM, said:
1064 - You have an error in your SQL syntax near '' at line 1
select parent_id from categories where categories_id =
[TEP STOP]
How do you fix this?
You didn't mention which file this was.... I would suggest you get an editing tool like JEdit and install the php plugin it finds these little errors for you. Probably a missing " or ' or ;.
Also Purchased (AP) Preselection (cuts this resource hogging query down to nothing) -- Contribution 3294
FedEx Automated Labels -- Contribution 2244
RMA Returns system -- Contribution 1136
Sort Products By Dropdown -- Contribution 4312
Ultimate SEO URLs -- Contribution 2823
Credit Class & Gift Voucher -- Contribution 282
Cross-Sell -- Contribution 5347
#19
Posted 15 August 2005, 14:06
#20
Posted 15 August 2005, 15:02
Low Stock Report contribution:
http://www.theliquidleaf.com/admin/stats_low_stock.php
Inventory Report:
http://www.theliquidleaf.com/admin/inventory_report.php
They both give the very same error.
I will try the original contributions on these.
========================
update
I found this problem. I had removed a product_to_category listing in the db and left the product listed thus the error.
Edited by modom, 15 August 2005, 16:37.














